Java Code Examples for android.view.View.setPadding()

The following are Jave code examples for showing how to use setPadding() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: FlycoTabLayout   File: SegmentTabLayout.java   View Source Code Vote up 7 votes
private void updateTabStyles() {
        for (int i = 0; i < mTabCount; i++) {
            View tabView = mTabsContainer.getChildAt(i);
            tabView.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
            TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
            tv_tab_title.setTextColor(i == mCurrentTab ? mTextSelectColor : mTextUnselectColor);
            tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextsize);
//            tv_tab_title.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
            if (mTextAllCaps) {
                tv_tab_title.setText(tv_tab_title.getText().toString().toUpperCase());
            }

            if (mTextBold == TEXT_BOLD_BOTH) {
                tv_tab_title.getPaint().setFakeBoldText(true);
            } else if (mTextBold == TEXT_BOLD_NONE) {
                tv_tab_title.getPaint().setFakeBoldText(false);
            }
        }
    }
 
Example 2
Project: XinFramework   File: TitleBar.java   View Source Code Vote up 7 votes
/**
 * Inflates a {@link View} with the given {@link Action}.
 *
 * @param action the action to inflate
 * @return a view
 */
private View inflateAction(Action action) {
    View view;
    if (TextUtils.isEmpty(action.getText())) {
        ImageView img = new ImageView(getContext());
        img.setImageResource(action.getDrawable());
        view = img;
    } else {
        TextView text = new TextView(getContext());
        text.setGravity(Gravity.CENTER);
        text.setText(action.getText());
        text.setTextSize(DEFAULT_ACTION_TEXT_SIZE);
        if (mActionTextColor != 0) {
            text.setTextColor(mActionTextColor);
        }
        view = text;
    }

    view.setPadding(mActionPadding, 0, mActionPadding, 0);
    view.setTag(action);
    view.setOnClickListener(this);
    return view;
}
 
Example 3
Project: MDWechat   File: SegmentTabLayout.java   View Source Code Vote up 7 votes
private void updateTabStyles() {
        for (int i = 0; i < mTabCount; i++) {
            View tabView = mTabsContainer.getChildAt(i);
            tabView.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
            TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
            tv_tab_title.setTextColor(i == mCurrentTab ? mTextSelectColor : mTextUnselectColor);
            tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextsize);
//            tv_tab_title.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
            if (mTextAllCaps) {
                tv_tab_title.setText(tv_tab_title.getText().toString().toUpperCase());
            }

            if (mTextBold == TEXT_BOLD_BOTH) {
                tv_tab_title.getPaint().setFakeBoldText(true);
            } else if (mTextBold == TEXT_BOLD_NONE) {
                tv_tab_title.getPaint().setFakeBoldText(false);
            }
        }
    }
 
Example 4
Project: Android_Songshuhui   File: SegmentTabLayout.java   View Source Code Vote up 7 votes
private void updateTabStyles() {
        for (int i = 0; i < mTabCount; i++) {
            View tabView = mTabsContainer.getChildAt(i);
            tabView.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
            TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
            tv_tab_title.setTextColor(i == mCurrentTab ? mTextSelectColor : mTextUnselectColor);
            tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextsize);
//            tv_tab_title.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
            if (mTextAllCaps) {
                tv_tab_title.setText(tv_tab_title.getText().toString().toUpperCase());
            }

            if (mTextBold == TEXT_BOLD_BOTH) {
                tv_tab_title.getPaint().setFakeBoldText(true);
            } else if (mTextBold == TEXT_BOLD_NONE) {
                tv_tab_title.getPaint().setFakeBoldText(false);
            }
        }
    }
 
Example 5
Project: GitHub   File: SegmentTabLayout.java   View Source Code Vote up 7 votes
private void updateTabStyles() {
        for (int i = 0; i < mTabCount; i++) {
            View tabView = mTabsContainer.getChildAt(i);
            tabView.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
            TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
            tv_tab_title.setTextColor(i == mCurrentTab ? mTextSelectColor : mTextUnselectColor);
            tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextsize);
//            tv_tab_title.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
            if (mTextAllCaps) {
                tv_tab_title.setText(tv_tab_title.getText().toString().toUpperCase());
            }

            if (mTextBold == TEXT_BOLD_BOTH) {
                tv_tab_title.getPaint().setFakeBoldText(true);
            } else if (mTextBold == TEXT_BOLD_NONE) {
                tv_tab_title.getPaint().setFakeBoldText(false);
            }
        }
    }
 
Example 6
Project: YCWeather   File: ViewUtil.java   View Source Code Vote up 6 votes
public static void setPadding(View view, int left, int top, int right, int bottom) {
    int scaledLeft = scaleValue(view.getContext(), left);
    int scaledTop = scaleValue(view.getContext(), top);
    int scaledRight = scaleValue(view.getContext(), right);
    int scaledBottom = scaleValue(view.getContext(), bottom);
    view.setPadding(scaledLeft, scaledTop, scaledRight, scaledBottom);
}
 
Example 7
Project: simple-share-android   File: SystemBarTintManager.java   View Source Code Vote up 6 votes
public static void setInsets(Activity context, View view) {
    if (Utils.hasKitKat()) {
        SystemBarTintManager tintManager = new SystemBarTintManager(context);
        SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
        view.setPadding(0, config.getPixelInsetTop(true), config.getPixelInsetRight(), 2*config.getPixelInsetBottom());
    }
}
 
Example 8
Project: SmartRefreshLayout   File: StatusBarUtil.java   View Source Code Vote up 6 votes
/** 增加View的高度以及paddingTop,增加的值为状态栏高度.一般是在沉浸式全屏给ToolBar用的 */
public static void setHeightAndPadding(Context context, View view) {
    if (Build.VERSION.SDK_INT >= MIN_API) {
        ViewGroup.LayoutParams lp = view.getLayoutParams();
        lp.height += getStatusBarHeight(context);//增高
        view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context),
                view.getPaddingRight(), view.getPaddingBottom());
    }
}
 
Example 9
Project: utilsLibrary   File: ActivityUtils.java   View Source Code Vote up 6 votes
/**
 * 设置透明状态栏并对某个view 拉伸,达到沉浸式状态栏的效果。仅支持19(含)~21(不含),
 * 5.0及以上版本建议使用 {@link #setStatusBarColor(Activity, int)}
 *
 * @param view
 */
public static void setTranslucentStatus(Activity activity, View view) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        view.setPadding(view.getPaddingLeft(),
                DeviceInfo.getStatusHeight(activity)+view.getPaddingTop(),
                view.getPaddingRight(),
                view.getPaddingBottom());
    }
}
 
Example 10
Project: Tree2View   File: TreeAdapter.java   View Source Code Vote up 6 votes
protected void setPadding(View v, int depth, int indent) {
  if (v == null || depth < 0) {
    throw new IllegalArgumentException("illegal params");
  }
  if (indent < 0) {
    indent = baseIndent;
  }
  v.setPadding(indent * (depth + 1),
          v.getPaddingTop(),
          v.getPaddingRight(),
          v.getPaddingBottom());
}
 
Example 11
Project: microMathematics   File: FormulaTermFunction.java   View Source Code Vote up 6 votes
@Override
public void updateTextSize()
{
    super.updateTextSize();
    final int hsp = getFormulaList().getDimen().get(ScaledDimensions.Type.HOR_SYMBOL_PADDING);
    if (functionTerm != null)
    {
        if (functionType == FunctionType.SQRT_LAYOUT || functionType == FunctionType.NTHRT_LAYOUT)
        {
            functionTerm.setWidth(getFormulaList().getDimen().get(ScaledDimensions.Type.SMALL_SYMBOL_SIZE));
            functionTerm.setPadding(0, 0, 0, 0);
        }
        else if (functionType == FunctionType.CONJUGATE_LAYOUT)
        {
            functionTerm.setPadding(hsp, 0, hsp, 0);
        }
        else if (functionType == FunctionType.FUNCTION_INDEX)
        {
            functionTerm.setPadding(0, 0, 0, 0);
        }
        else
        {
            functionTerm.setPadding(0, 0, hsp, 0);
        }
    }
    if (functionType == FunctionType.NTHRT_LAYOUT)
    {
        View nthrtPoverLayout = layout.findViewById(R.id.nthrt_power_layout);
        if (nthrtPoverLayout != null)
        {
            nthrtPoverLayout.setPadding(hsp, 0, hsp, 0);
        }
    }
}
 
Example 12
Project: FastLib   File: SnackBarUtil.java   View Source Code Vote up 6 votes
/**
 * 添加SnackBar视图
 * <p>在{@link #show()}之后调用</p>
 *
 * @param layoutId 布局文件
 * @param params   布局参数
 */
public static void addView(@LayoutRes final int layoutId, @NonNull final ViewGroup.LayoutParams params) {
    final View view = getView();
    if (view != null) {
        view.setPadding(0, 0, 0, 0);
        Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) view;
        View child = LayoutInflater.from(view.getContext()).inflate(layoutId, null);
        layout.addView(child, -1, params);
    }
}
 
Example 13
Project: SimpleUILauncher   File: ShortcutAndWidgetContainer.java   View Source Code Vote up 6 votes
public void measureChild(View child) {
    final DeviceProfile grid = mLauncher.getDeviceProfile();
    final int cellWidth = mCellWidth;
    final int cellHeight = mCellHeight;
    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
    if (!lp.isFullscreen) {
        // 把计算的结果封装到LayoutParams中,用于布局item的时候进行调用
        lp.setup(cellWidth, cellHeight, mWidthGap, mHeightGap, invertLayoutHorizontally(), mCountX);// 核心代码

        if (child instanceof LauncherAppWidgetHostView) {
            // Widgets have their own padding, so skip
        } else {
            // Otherwise, center the icon/folder
            int cHeight = getCellContentHeight();
            int cellPaddingY = (int) Math.max(0, ((lp.height - cHeight) / 2f));
            int cellPaddingX = (int) (grid.edgeMarginPx / 2f);
            child.setPadding(cellPaddingX, cellPaddingY, cellPaddingX, 0);
        }
    } else {
        lp.x = 0;
        lp.y = 0;
        lp.width = getMeasuredWidth();
        lp.height = getMeasuredHeight();
    }
    int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
    int childheightMeasureSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
    child.measure(childWidthMeasureSpec, childheightMeasureSpec);
}
 
Example 14
Project: HeadlineNews   File: StatusBarUtil.java   View Source Code Vote up 6 votes
/** 增加View的高度以及paddingTop,增加的值为状态栏高度.一般是在沉浸式全屏给ToolBar用的 */
public static void setHeightAndPadding(Context context, View view) {
    if (Build.VERSION.SDK_INT >= MIN_API) {
        ViewGroup.LayoutParams lp = view.getLayoutParams();
        lp.height += getStatusBarHeight(context);//增高
        view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context),
                view.getPaddingRight(), view.getPaddingBottom());
    }
}
 
Example 15
Project: QMUI_Android   File: QMUIViewHelper.java   View Source Code Vote up 6 votes
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void setBackgroundKeepingPadding(View view, Drawable drawable) {
    int[] padding = new int[]{view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom()};
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setBackground(drawable);
    } else {
        view.setBackgroundDrawable(drawable);
    }
    view.setPadding(padding[0], padding[1], padding[2], padding[3]);
}
 
Example 16
Project: BilibiliClient   File: SystemBarHelper.java   View Source Code Vote up 6 votes
/**
 * 增加View的paddingTop,增加的值为状态栏高度
 */
public static void setPadding(Context context, View view) {

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context),
        view.getPaddingRight(), view.getPaddingBottom());
  }
}
 
Example 17
Project: letv   File: ViewCompat.java   View Source Code Vote up 5 votes
public void setPaddingRelative(View view, int start, int top, int end, int bottom) {
    view.setPadding(start, top, end, bottom);
}
 
Example 18
Project: Aurora   File: DeviceUtils.java   View Source Code Vote up 5 votes
public static void hideAnimatedView(View view) {
    if (PRE_HC && view != null)
        view.setPadding(view.getWidth(), 0, 0, 0);
}
 
Example 19
Project: StatusBarFits   File: StatusBarFits.java   View Source Code Vote up 5 votes
public static void setTransparent(Activity activity, View needOffsetView) {

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            return;
        }

        ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
        if (contentView.getChildAt(0) == null) {
            return;
        }
        else if (contentView.getChildCount() > 1 && contentView.getChildAt(1) instanceof StatusBarView) {
            contentView.removeViewAt(1);
        }
        if (contentView.getChildAt(0) instanceof DrawerLayout) {
            // 让DrawerLayout中的布局内容可以延伸到状态栏
            // 为了实现上述效果,设置DrawerLayout以及两个子View的fitsSystemWindows为false
            // 这个带来了一个问题:
            // DrawerLayout的内容布局会从屏幕最上方开始绘制,
            // 所以需要下移避免被状态栏遮挡的布局,手动设置marginTop。
            DrawerLayout drawerLayout = (DrawerLayout) contentView.getChildAt(0);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
            } else {
                activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            }

            ViewGroup drawerLayoutContent = (ViewGroup) drawerLayout.getChildAt(0);
            //如果DrawerLayout的内容布局第一个子View是我们自己的StatusBarView就将它reomve。
            if (drawerLayoutContent.getChildAt(0) instanceof StatusBarView) {
                drawerLayoutContent.removeViewAt(0);
            }

            View drawerLayoutContentReal = drawerLayoutContent.getChildAt(0);

            // 内容布局不是 LinearLayout 时,清除多余的StatusBarHeight。
            if (!(drawerLayoutContent instanceof LinearLayout) &&
                    drawerLayoutContentReal != null &&
                    drawerLayoutContentReal.getTag(R.id.tag_top) != null &&
                    drawerLayoutContentReal.getTag(R.id.tag_top).equals(TAG_ADD_TOP)) {
                drawerLayoutContentReal.setPadding(
                        drawerLayoutContentReal.getPaddingLeft(),
                        drawerLayoutContentReal.getPaddingTop() - getStatusBarHeight(activity),
                        drawerLayoutContentReal.getPaddingRight(),
                        drawerLayoutContentReal.getPaddingBottom()
                );
                drawerLayoutContentReal.setTag(R.id.tag_top, TAG_REMOVE_TOP);
            }

            // 设置属性
            setDrawerLayoutProperty(drawerLayout, drawerLayoutContent);

        } else if (contentView.getChildAt(0) instanceof CoordinatorLayout) {

            transparentStatusBar(activity);
            setRootViewPaddingTop(activity, PaddingTop.removePaddingTop);

        } else {
            transparentStatusBar(activity);

            ViewCompat.setFitsSystemWindows(contentView.getChildAt(0), false);
            ViewCompat.requestApplyInsets(contentView.getChildAt(0));
        }

        if (needOffsetView != null && needOffsetView.getTag(R.id.tag_need_offset) == null) {

            ViewGroup.MarginLayoutParams layoutParams =
                    (ViewGroup.MarginLayoutParams) needOffsetView.getLayoutParams();
            layoutParams.setMargins(
                    layoutParams.leftMargin,
                    layoutParams.topMargin + getStatusBarHeight(activity),
                    layoutParams.rightMargin,
                    layoutParams.bottomMargin);

            needOffsetView.setTag(R.id.tag_need_offset, TAG_NEED_OFFNET);
        }
    }
 
Example 20
Project: QMUI_Android   File: QMUIViewHelper.java   View Source Code Vote up 3 votes
/**
 * 对 View 设置 paddingLeft
 *
 * @param view  需要被设置的 View
 * @param value 设置的值
 */
public static void setPaddingLeft(View view, int value) {
    view.setPadding(value, view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom());
}