コード例 #1
0
 /** 设置未读消息偏移,原点为文字的右上角.当控件高度固定,消息提示位置易控制,显示效果佳 */
 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);
   }
 }
コード例 #2
0
 private void applyMarginInsets(
     MarginLayoutParams lp, Object insets, int drawerGravity, boolean topOnly) {
   WindowInsets wi = (WindowInsets) insets;
   if (drawerGravity == Gravity.LEFT) {
     wi =
         wi.replaceSystemWindowInsets(
             wi.getSystemWindowInsetLeft(),
             wi.getSystemWindowInsetTop(),
             0,
             wi.getSystemWindowInsetBottom());
   } else if (drawerGravity == Gravity.RIGHT) {
     wi =
         wi.replaceSystemWindowInsets(
             0,
             wi.getSystemWindowInsetTop(),
             wi.getSystemWindowInsetRight(),
             wi.getSystemWindowInsetBottom());
   }
   lp.leftMargin = wi.getSystemWindowInsetLeft();
   lp.topMargin = topOnly ? 0 : wi.getSystemWindowInsetTop();
   lp.rightMargin = wi.getSystemWindowInsetRight();
   lp.bottomMargin = wi.getSystemWindowInsetBottom();
 }
コード例 #3
0
ファイル: ParallaxView.java プロジェクト: alexmirash/Demo
 public void setOffset(float offset) {
   int parallaxOffset = (int) (offset * mParallaxValue);
   mLayoutParams.leftMargin = parallaxOffset;
   mLayoutParams.rightMargin = -parallaxOffset;
   requestLayout();
 }