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

The following examples show how to use android.view.View#setPadding() . These examples are extracted from open source projects. 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
public SmartViewHolder(View itemView, AdapterView.OnItemClickListener mListener) {
    super(itemView);
    this.mListener = mListener;
    itemView.setOnClickListener(this);

    /*
     * 设置水波纹背景
     */
    if (itemView.getBackground() == null) {
        TypedValue typedValue = new TypedValue();
        Resources.Theme theme = itemView.getContext().getTheme();
        int top = itemView.getPaddingTop();
        int bottom = itemView.getPaddingBottom();
        int left = itemView.getPaddingLeft();
        int right = itemView.getPaddingRight();
        if (theme.resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true)) {
            itemView.setBackgroundResource(typedValue.resourceId);
        }
        itemView.setPadding(left, top, right, bottom);
    }
}
 
Example 2
@Keep
public void setTopPadding(float value) {
    topPadding = value;
    if (fragment != null && getParent() != null) {
        View view = fragment.getFragmentView();
        int additionalPadding = 0;
        if (additionalContextView != null && additionalContextView.getVisibility() == VISIBLE && additionalContextView.getParent() != null) {
            additionalPadding = AndroidUtilities.dp(36);
        }
        if (view != null && getParent() != null) {
            view.setPadding(0, (int) topPadding + additionalPadding, 0, 0);
        }
        if (isLocation && additionalContextView != null) {
            ((LayoutParams) additionalContextView.getLayoutParams()).topMargin = -AndroidUtilities.dp(36) - (int) topPadding;
        }
    }
}
 
Example 3
Source Project: AutoLayout   File: AutoUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static void autoPadding(View view)
{
    Object tag = view.getTag(R.id.id_tag_autolayout_padding);
    if (tag != null) return;
    view.setTag(R.id.id_tag_autolayout_padding, "Just Identify");

    int l = view.getPaddingLeft();
    int t = view.getPaddingTop();
    int r = view.getPaddingRight();
    int b = view.getPaddingBottom();

    l = getPercentWidthSize(l);
    t = getPercentHeightSize(t);
    r = getPercentWidthSize(r);
    b = getPercentHeightSize(b);

    view.setPadding(l, t, r, b);
}
 
Example 4
Source Project: KUAS-AP-Material   File: Utils.java    License: MIT License 6 votes vote down vote up
/**
 * Sets the background for a view while preserving its current padding. If the background drawable
 * has its own padding, that padding will be added to the current padding.
 *
 * @param view               View to receive the new background.
 * @param backgroundDrawable Drawable to set as new background.
 */
public static void setBackgroundAndKeepPadding(View view, Drawable backgroundDrawable) {
	Rect drawablePadding = new Rect();
	backgroundDrawable.getPadding(drawablePadding);
	int top = view.getPaddingTop() + drawablePadding.top;
	int left = view.getPaddingLeft() + drawablePadding.left;
	int right = view.getPaddingRight() + drawablePadding.right;
	int bottom = view.getPaddingBottom() + drawablePadding.bottom;
	if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
		//noinspection deprecation
		view.setBackgroundDrawable(backgroundDrawable);
	} else {
		view.setBackground(backgroundDrawable);
	}
	view.setPadding(left, top, right, bottom);
}
 
Example 5
public void measureChild(View child) {
    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
    if (!lp.isFullscreen) {
        final DeviceProfile profile = mLauncher.getDeviceProfile();

        if (child instanceof LauncherAppWidgetHostView) {
            lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX,
                    profile.appWidgetScale.x, profile.appWidgetScale.y);
            // Widgets have their own padding
        } else {
            lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX);
            // Center the icon/folder
            int cHeight = getCellContentHeight();
            int cellPaddingY = (int) Math.max(0, ((lp.height - cHeight) / 2f));
            int cellPaddingX = (int) (profile.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 6
Source Project: SmartChart   File: StatusBarUtil.java    License: Apache License 2.0 5 votes vote down vote up
/** 增加View的paddingTop,增加的值为状态栏高度 (智能判断,并设置高度)*/
public static void setPaddingSmart(Context context, View view) {
    if (Build.VERSION.SDK_INT >= MIN_API) {
        ViewGroup.LayoutParams lp = view.getLayoutParams();
        if (lp != null && lp.height > 0) {
            lp.height += getStatusBarHeight(context);//增高
        }
        view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context),
                view.getPaddingRight(), view.getPaddingBottom());
    }
}
 
Example 7
Source Project: FastLib   File: SnackBarUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 添加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 8
/** 增加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
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);
    int horizontalMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
    int verticalMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
    int topMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 56, getResources().getDisplayMetrics());

    if (view != null) {
        view.setPadding(horizontalMargin, topMargin, horizontalMargin, verticalMargin);
    }
    return view;
}
 
Example 10
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);
    int horizontalMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
    int verticalMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
    int topMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 56, getResources().getDisplayMetrics());

    if (view != null) {
        view.setPadding(horizontalMargin, topMargin, horizontalMargin, verticalMargin);
    }
    return view;
}
 
Example 11
@Override
protected void onBindView(final View view) {
    super.onBindView(view);
    // On pre-L devices, PreferenceCategoryWithButtonStyle is reused for PreferenceCategory,
    // which needs a top padding of 16dp; we don't want this top padding for
    // PreferenceCategoryWithButton views.
    view.setPadding(view.getPaddingLeft(), 0, view.getPaddingRight(), view.getPaddingBottom());
    View button = view.findViewById(android.R.id.icon);
    button.setOnClickListener(this);

    if (!TextUtils.isEmpty(mContentDescription)) {
        button.setContentDescription(mContentDescription);
    }
}
 
Example 12
Source Project: TSnackBar   File: TSnackbar.java    License: Apache License 2.0 5 votes vote down vote up
private static void updateTopBottomPadding(View view, int topPadding, int bottomPadding) {
    if (ViewCompat.isPaddingRelative(view)) {
        ViewCompat.setPaddingRelative(view,
                ViewCompat.getPaddingStart(view), topPadding,
                ViewCompat.getPaddingEnd(view), bottomPadding);
    } else {
        view.setPadding(view.getPaddingLeft(), topPadding,
                view.getPaddingRight(), bottomPadding);
    }
}
 
Example 13
Source Project: YiBo   File: ThemeUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void setHeaderUserSelector(View headerCornerTab) {
	if (headerCornerTab == null) {
		return;
	}
	Theme theme = ThemeUtil.createTheme(headerCornerTab.getContext());
	EditText etFilterName = (EditText)headerCornerTab.findViewById(R.id.etFilterName);
	Button btnSearch = (Button)headerCornerTab.findViewById(R.id.btnSearch);
	headerCornerTab.setBackgroundDrawable(theme.getDrawable("bg_header_corner_tab"));
	int padding8 = theme.dip2px(8);
	headerCornerTab.setPadding(padding8, padding8, padding8, padding8);
	etFilterName.setBackgroundDrawable(theme.getDrawable("bg_input_frame_left_half"));
	btnSearch.setBackgroundDrawable(theme.getDrawable("selector_btn_search"));
}
 
Example 14
Source Project: Yuan-WanAndroid   File: StatusBarUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 *  增加View的paddingTop,增加的值为状态栏高度 (智能判断,并设置高度)
 */
public static void setPaddingSmart(Context context, View view) {
    if (Build.VERSION.SDK_INT >= MIN_API) {
        ViewGroup.LayoutParams lp = view.getLayoutParams();
        if (lp != null && lp.height > 0) {
            lp.height += getStatusBarHeight(context);//增高
        }
        view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + getStatusBarHeight(context),
                view.getPaddingRight(), view.getPaddingBottom());
    }
}
 
Example 15
Source Project: PDFCreatorAndroid   File: PDFLineSeparatorView.java    License: MIT License 5 votes vote down vote up
public PDFLineSeparatorView(Context context) {
    super(context);

    View separatorLine = new View(context);
    LinearLayout.LayoutParams separatorLayoutParam = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1);
    separatorLine.setPadding(0, 5, 0, 5);
    separatorLine.setLayoutParams(separatorLayoutParam);

    super.setView(separatorLine);
}
 
Example 16
Source Project: Matisse   File: SizeUtils.java    License: Apache License 2.0 5 votes vote down vote up
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 17
Source Project: AndroidNavigation   File: AppUtils.java    License: MIT License 5 votes vote down vote up
public static void appendStatusBarPadding(Context context, View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (view != null) {
            int statusBarHeight = getStatusBarHeight(context);
            ViewGroup.LayoutParams lp = view.getLayoutParams();
            if (lp != null && lp.height > 0) {
                lp.height += statusBarHeight;//增高
            }
            view.setPadding(view.getPaddingLeft(), view.getPaddingTop() + statusBarHeight,
                    view.getPaddingRight(), view.getPaddingBottom());
        }
    }
}
 
Example 18
Source Project: FairEmail   File: Helper.java    License: GNU General Public License v3.0 5 votes vote down vote up
static void hide(View view) {
    view.setPadding(0, 0, 0, 0);

    ViewGroup.LayoutParams lparam = view.getLayoutParams();
    lparam.width = 0;
    lparam.height = 0;
    if (lparam instanceof ConstraintLayout.LayoutParams)
        ((ConstraintLayout.LayoutParams) lparam).setMargins(0, 0, 0, 0);
    view.setLayoutParams(lparam);
}
 
Example 19
Source Project: android_9.0.0_r45   File: RemoteViews.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void apply(View root, ViewGroup rootParent, OnClickHandler handler) {
    final View target = root.findViewById(viewId);
    if (target == null) return;
    target.setPadding(left, top, right, bottom);
}
 
Example 20
/**
 * Applies the dialog's bottom padding to the view of a specific area.
 *
 * @param area The area, the view, the padding should be applied to, corresponds to, as an instance
 *             of the class {@link Area}. The area may not be null
 * @param view The view, the padding should be applied to, as an instance of the class {@link View}.
 *             The view may not be null
 */
private void applyDialogPaddingBottom(@NonNull final Area area, @NonNull final View view) {
    if (area != Area.HEADER && area != Area.BUTTON_BAR) {
        view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), view.getPaddingRight(),
                dialogPadding[3]);
    }
}