Java Code Examples for com.flyco.tablayout.widget.MsgView#setLayoutParams()
The following examples show how to use
com.flyco.tablayout.widget.MsgView#setLayoutParams() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SegmentTabLayout.java From likequanmintv with Apache License 2.0 | 6 votes |
/** * 设置提示红点偏移,注意 * 1.控件为固定高度:参照点为tab内容的右上角 * 2.控件高度不固定(WRAP_CONTENT):参照点为tab内容的右上角,此时高度已是红点的最高显示范围,所以这时bottomPadding其实就是topPadding */ public void setMsgMargin(int position, float leftPadding, float bottomPadding) { if (position >= mTabCount) { position = mTabCount - 1; } View tabView = mTabsContainer.getChildAt(position); MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip); if (tipView != null) { TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title); mTextPaint.setTextSize(mTextsize); float textWidth = mTextPaint.measureText(tv_tab_title.getText().toString()); float textHeight = mTextPaint.descent() - mTextPaint.ascent(); MarginLayoutParams lp = (MarginLayoutParams) tipView.getLayoutParams(); lp.leftMargin = dp2px(leftPadding); lp.topMargin = mHeight > 0 ? (int) (mHeight - textHeight) / 2 - dp2px(bottomPadding) : dp2px(bottomPadding); tipView.setLayoutParams(lp); } }
Example 2
Source File: SlidingTabLayout.java From likequanmintv with Apache License 2.0 | 6 votes |
/** 设置未读消息偏移,原点为文字的右上角.当控件高度固定,消息提示位置易控制,显示效果佳 */ public void setMsgMargin(int position, float leftPadding, float bottomPadding) { if (position >= mTabCount) { position = mTabCount - 1; } View tabView = mTabsContainer.getChildAt(position); MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip); if (tipView != null) { TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title); mTextPaint.setTextSize(mTextsize); float textWidth = mTextPaint.measureText(tv_tab_title.getText().toString()); float textHeight = mTextPaint.descent() - mTextPaint.ascent(); MarginLayoutParams lp = (MarginLayoutParams) tipView.getLayoutParams(); lp.leftMargin = mTabWidth >= 0 ? (int) (mTabWidth / 2 + textWidth / 2 + dp2px(leftPadding)) : (int) (mTabPadding + textWidth + dp2px(leftPadding)); lp.topMargin = mHeight > 0 ? (int) (mHeight - textHeight) / 2 - dp2px(bottomPadding) : 0; tipView.setLayoutParams(lp); } }
Example 3
Source File: SegmentTabLayout.java From FlycoTabLayout with MIT License | 6 votes |
/** * 设置提示红点偏移,注意 * 1.控件为固定高度:参照点为tab内容的右上角 * 2.控件高度不固定(WRAP_CONTENT):参照点为tab内容的右上角,此时高度已是红点的最高显示范围,所以这时bottomPadding其实就是topPadding */ public void setMsgMargin(int position, float leftPadding, float bottomPadding) { if (position >= mTabCount) { position = mTabCount - 1; } View tabView = mTabsContainer.getChildAt(position); MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip); if (tipView != null) { TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title); mTextPaint.setTextSize(mTextsize); float textWidth = mTextPaint.measureText(tv_tab_title.getText().toString()); float textHeight = mTextPaint.descent() - mTextPaint.ascent(); MarginLayoutParams lp = (MarginLayoutParams) tipView.getLayoutParams(); lp.leftMargin = dp2px(leftPadding); lp.topMargin = mHeight > 0 ? (int) (mHeight - textHeight) / 2 - dp2px(bottomPadding) : dp2px(bottomPadding); tipView.setLayoutParams(lp); } }
Example 4
Source File: SlidingTabLayout.java From FlycoTabLayout with MIT License | 6 votes |
/** 设置未读消息偏移,原点为文字的右上角.当控件高度固定,消息提示位置易控制,显示效果佳 */ public void setMsgMargin(int position, float leftPadding, float bottomPadding) { if (position >= mTabCount) { position = mTabCount - 1; } View tabView = mTabsContainer.getChildAt(position); MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip); if (tipView != null) { TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title); mTextPaint.setTextSize(mTextsize); float textWidth = mTextPaint.measureText(tv_tab_title.getText().toString()); float textHeight = mTextPaint.descent() - mTextPaint.ascent(); MarginLayoutParams lp = (MarginLayoutParams) tipView.getLayoutParams(); lp.leftMargin = mTabWidth >= 0 ? (int) (mTabWidth / 2 + textWidth / 2 + dp2px(leftPadding)) : (int) (mTabPadding + textWidth + dp2px(leftPadding)); lp.topMargin = mHeight > 0 ? (int) (mHeight - textHeight) / 2 - dp2px(bottomPadding) : 0; tipView.setLayoutParams(lp); } }
Example 5
Source File: CommonTabLayout.java From likequanmintv with Apache License 2.0 | 5 votes |
/** * 设置提示红点偏移,注意 * 1.控件为固定高度:参照点为tab内容的右上角 * 2.控件高度不固定(WRAP_CONTENT):参照点为tab内容的右上角,此时高度已是红点的最高显示范围,所以这时bottomPadding其实就是topPadding */ public void setMsgMargin(int position, float leftPadding, float bottomPadding) { if (position >= mTabCount) { position = mTabCount - 1; } View tabView = mTabsContainer.getChildAt(position); MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip); if (tipView != null) { TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title); mTextPaint.setTextSize(mTextsize); float textWidth = mTextPaint.measureText(tv_tab_title.getText().toString()); float textHeight = mTextPaint.descent() - mTextPaint.ascent(); MarginLayoutParams lp = (MarginLayoutParams) tipView.getLayoutParams(); float iconH = mIconHeight; float margin = 0; if (mIconVisible) { if (iconH <= 0) { iconH = mContext.getResources().getDrawable(mTabEntitys.get(position).getTabSelectedIcon()).getIntrinsicHeight(); } margin = mIconMargin; } if (mIconGravity == Gravity.TOP || mIconGravity == Gravity.BOTTOM) { lp.leftMargin = dp2px(leftPadding); lp.topMargin = mHeight > 0 ? (int) (mHeight - textHeight - iconH - margin) / 2 - dp2px(bottomPadding) : dp2px(bottomPadding); } else { lp.leftMargin = dp2px(leftPadding); lp.topMargin = mHeight > 0 ? (int) (mHeight - Math.max(textHeight, iconH)) / 2 - dp2px(bottomPadding) : dp2px(bottomPadding); } tipView.setLayoutParams(lp); } }
Example 6
Source File: UnreadMsgUtils.java From likequanmintv with Apache License 2.0 | 5 votes |
public static void show(MsgView msgView, int num) { if (msgView == null) { return; } RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) msgView.getLayoutParams(); DisplayMetrics dm = msgView.getResources().getDisplayMetrics(); msgView.setVisibility(View.VISIBLE); if (num <= 0) {//圆点,设置默认宽高 msgView.setStrokeWidth(0); msgView.setText(""); lp.width = (int) (5 * dm.density); lp.height = (int) (5 * dm.density); msgView.setLayoutParams(lp); } else { lp.height = (int) (18 * dm.density); if (num > 0 && num < 10) {//圆 lp.width = (int) (18 * dm.density); msgView.setText(num + ""); } else if (num > 9 && num < 100) {//圆角矩形,圆角是高度的一半,设置默认padding lp.width = RelativeLayout.LayoutParams.WRAP_CONTENT; msgView.setPadding((int) (6 * dm.density), 0, (int) (6 * dm.density), 0); msgView.setText(num + ""); } else {//数字超过两位,显示99+ lp.width = RelativeLayout.LayoutParams.WRAP_CONTENT; msgView.setPadding((int) (6 * dm.density), 0, (int) (6 * dm.density), 0); msgView.setText("99+"); } msgView.setLayoutParams(lp); } }
Example 7
Source File: UnreadMsgUtils.java From likequanmintv with Apache License 2.0 | 5 votes |
public static void setSize(MsgView rtv, int size) { if (rtv == null) { return; } RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) rtv.getLayoutParams(); lp.width = size; lp.height = size; rtv.setLayoutParams(lp); }
Example 8
Source File: CommonTabLayout.java From FlycoTabLayout with MIT License | 5 votes |
/** * 设置提示红点偏移,注意 * 1.控件为固定高度:参照点为tab内容的右上角 * 2.控件高度不固定(WRAP_CONTENT):参照点为tab内容的右上角,此时高度已是红点的最高显示范围,所以这时bottomPadding其实就是topPadding */ public void setMsgMargin(int position, float leftPadding, float bottomPadding) { if (position >= mTabCount) { position = mTabCount - 1; } View tabView = mTabsContainer.getChildAt(position); MsgView tipView = (MsgView) tabView.findViewById(R.id.rtv_msg_tip); if (tipView != null) { TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title); mTextPaint.setTextSize(mTextsize); float textWidth = mTextPaint.measureText(tv_tab_title.getText().toString()); float textHeight = mTextPaint.descent() - mTextPaint.ascent(); MarginLayoutParams lp = (MarginLayoutParams) tipView.getLayoutParams(); float iconH = mIconHeight; float margin = 0; if (mIconVisible) { if (iconH <= 0) { iconH = mContext.getResources().getDrawable(mTabEntitys.get(position).getTabSelectedIcon()).getIntrinsicHeight(); } margin = mIconMargin; } if (mIconGravity == Gravity.TOP || mIconGravity == Gravity.BOTTOM) { lp.leftMargin = dp2px(leftPadding); lp.topMargin = mHeight > 0 ? (int) (mHeight - textHeight - iconH - margin) / 2 - dp2px(bottomPadding) : dp2px(bottomPadding); } else { lp.leftMargin = dp2px(leftPadding); lp.topMargin = mHeight > 0 ? (int) (mHeight - Math.max(textHeight, iconH)) / 2 - dp2px(bottomPadding) : dp2px(bottomPadding); } tipView.setLayoutParams(lp); } }
Example 9
Source File: UnreadMsgUtils.java From FlycoTabLayout with MIT License | 5 votes |
public static void show(MsgView msgView, int num) { if (msgView == null) { return; } RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) msgView.getLayoutParams(); DisplayMetrics dm = msgView.getResources().getDisplayMetrics(); msgView.setVisibility(View.VISIBLE); if (num <= 0) {//圆点,设置默认宽高 msgView.setStrokeWidth(0); msgView.setText(""); lp.width = (int) (5 * dm.density); lp.height = (int) (5 * dm.density); msgView.setLayoutParams(lp); } else { lp.height = (int) (18 * dm.density); if (num > 0 && num < 10) {//圆 lp.width = (int) (18 * dm.density); msgView.setText(num + ""); } else if (num > 9 && num < 100) {//圆角矩形,圆角是高度的一半,设置默认padding lp.width = RelativeLayout.LayoutParams.WRAP_CONTENT; msgView.setPadding((int) (6 * dm.density), 0, (int) (6 * dm.density), 0); msgView.setText(num + ""); } else {//数字超过两位,显示99+ lp.width = RelativeLayout.LayoutParams.WRAP_CONTENT; msgView.setPadding((int) (6 * dm.density), 0, (int) (6 * dm.density), 0); msgView.setText("99+"); } msgView.setLayoutParams(lp); } }
Example 10
Source File: UnreadMsgUtils.java From FlycoTabLayout with MIT License | 5 votes |
public static void setSize(MsgView rtv, int size) { if (rtv == null) { return; } RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) rtv.getLayoutParams(); lp.width = size; lp.height = size; rtv.setLayoutParams(lp); }