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

The following examples show how to use android.view.View#setPaddingRelative() . 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: AppOpsDetails.java    From AppOpsXposed with GNU General Public License v3.0 6 votes vote down vote up
private void setAppLabelAndIcon(PackageInfo pkgInfo) {
    final View appSnippet = mRootView.findViewById(R.id.app_snippet);
    appSnippet.setPaddingRelative(0, appSnippet.getPaddingTop(), 0, appSnippet.getPaddingBottom());

    ImageView icon = (ImageView) appSnippet.findViewById(R.id.app_icon);
    icon.setImageDrawable(mPm.getApplicationIcon(pkgInfo.applicationInfo));
    // Set application name.
    TextView label = (TextView) appSnippet.findViewById(R.id.app_name);
    label.setText(mPm.getApplicationLabel(pkgInfo.applicationInfo));
    // Version number of application
    mAppVersion = (TextView) appSnippet.findViewById(R.id.app_size);

    final StringBuilder sb = new StringBuilder(pkgInfo.packageName);

    if (pkgInfo.versionName != null) {
        sb.append("\n");
        sb.append(getActivity().getString(R.string.version_text, pkgInfo.versionName));
    }

    mAppVersion.setText(sb);
}
 
Example 2
Source File: AndroidBarUtils.java    From AndroidBarUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 设置BarPaddingTop
 *
 * @param context Activity
 * @param view    View[ToolBar、TitleBar、navigationView.getHeaderView(0)]
 */
public static void setBarPaddingTop(Activity context, View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        int paddingStart = view.getPaddingStart();
        int paddingEnd = view.getPaddingEnd();
        int paddingBottom = view.getPaddingBottom();
        int statusBarHeight = getStatusBarHeight(context);
        //改变titleBar的高度
        ViewGroup.LayoutParams lp = view.getLayoutParams();
        lp.height += statusBarHeight;
        view.setLayoutParams(lp);
        //设置paddingTop
        view.setPaddingRelative(paddingStart, statusBarHeight, paddingEnd, paddingBottom);
    }
}
 
Example 3
Source File: ApiCompatibilityUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @see android.view.View#setPaddingRelative(int, int, int, int)
 */
public static void setPaddingRelative(View view, int start, int top, int end, int bottom) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        view.setPaddingRelative(start, top, end, bottom);
    } else {
        // Before JB MR1, all layouts are left-to-right, so start == left, etc.
        view.setPadding(start, top, end, bottom);
    }
}
 
Example 4
Source File: DrawerUIUtils.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * helper to set the vertical padding including the extra padding for deeper item hirachy level to the DrawerItems
 * this is required because on API Level 17 the padding is ignored which is set via the XML
 *
 * @param v
 * @param level
 */
public static void setDrawerVerticalPadding(View v, int level) {
    int verticalPadding = v.getContext().getResources().getDimensionPixelSize(R.dimen.material_drawer_vertical_padding);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        v.setPaddingRelative(verticalPadding * level, 0, verticalPadding, 0);
    } else {
        v.setPadding(verticalPadding * level, 0, verticalPadding, 0);
    }
}
 
Example 5
Source File: ViewUtils.java    From FCM-for-Mojo with GNU General Public License v3.0 4 votes vote down vote up
public static void setPaddingVertical(View v, @Px int paddingVertical) {
    v.setPaddingRelative(v.getPaddingStart(), paddingVertical, v.getPaddingEnd(), paddingVertical);
}
 
Example 6
Source File: ViewCompatJellybeanMr1.java    From letv with Apache License 2.0 4 votes vote down vote up
public static void setPaddingRelative(View view, int start, int top, int end, int bottom) {
    view.setPaddingRelative(start, top, end, bottom);
}
 
Example 7
Source File: ViewUtils.java    From android-proguards with Apache License 2.0 4 votes vote down vote up
public static void setPaddingStart(View view, int paddingStart) {
    view.setPaddingRelative(paddingStart,
            view.getPaddingTop(),
            view.getPaddingEnd(),
            view.getPaddingBottom());
}
 
Example 8
Source File: ViewUtils.java    From android-proguards with Apache License 2.0 4 votes vote down vote up
public static void setPaddingTop(View view, int paddingTop) {
    view.setPaddingRelative(view.getPaddingStart(),
            paddingTop,
            view.getPaddingEnd(),
            view.getPaddingBottom());
}
 
Example 9
Source File: ViewUtils.java    From android-proguards with Apache License 2.0 4 votes vote down vote up
public static void setPaddingEnd(View view, int paddingEnd) {
    view.setPaddingRelative(view.getPaddingStart(),
            view.getPaddingTop(),
            paddingEnd,
            view.getPaddingBottom());
}
 
Example 10
Source File: ViewUtils.java    From android-proguards with Apache License 2.0 4 votes vote down vote up
public static void setPaddingBottom(View view, int paddingBottom) {
    view.setPaddingRelative(view.getPaddingStart(),
            view.getPaddingTop(),
            view.getPaddingEnd(),
            paddingBottom);
}
 
Example 11
Source File: ViewCompatJellybeanMr1.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public static void setPaddingRelative(View view, int start, int top, int end, int bottom) {
    view.setPaddingRelative(start, top, end, bottom);
}
 
Example 12
Source File: FloatingToolbar.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public List<MenuItem> layoutMainPanelItems(List<MenuItem> menuItems, final int toolbarWidth) {
    int availableWidth = toolbarWidth;
    final LinkedList<MenuItem> remainingMenuItems = new LinkedList<>(menuItems);
    /*final LinkedList<MenuItem> overflowMenuItems = new LinkedList<>();
    for (MenuItem menuItem : menuItems) {
        if (menuItem.requiresOverflow()) {
            overflowMenuItems.add(menuItem); TODO
        } else {
            remainingMenuItems.add(menuItem);
        }
    }
    remainingMenuItems.addAll(overflowMenuItems);*/
    mMainPanel.removeAllViews();
    mMainPanel.setPaddingRelative(0, 0, 0, 0);
    boolean isFirstItem = true;
    while (!remainingMenuItems.isEmpty()) {
        final MenuItem menuItem = remainingMenuItems.peek();
        /*if (!isFirstItem && menuItem.requiresOverflow()) {
            break;
        }*/
        final View menuItemButton = createMenuItemButton(mContext, menuItem, mIconTextSpacing);
        if (menuItemButton instanceof LinearLayout) {
            ((LinearLayout) menuItemButton).setGravity(Gravity.CENTER);
        }
        if (isFirstItem) {
            menuItemButton.setPaddingRelative((int) (1.5 * menuItemButton.getPaddingStart()), menuItemButton.getPaddingTop(), menuItemButton.getPaddingEnd(), menuItemButton.getPaddingBottom());
        }
        boolean isLastItem = remainingMenuItems.size() == 1;
        if (isLastItem) {
            menuItemButton.setPaddingRelative(menuItemButton.getPaddingStart(), menuItemButton.getPaddingTop(), (int) (1.5 * menuItemButton.getPaddingEnd()), menuItemButton.getPaddingBottom());
        }
        menuItemButton.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
        final int menuItemButtonWidth = Math.min(menuItemButton.getMeasuredWidth(), toolbarWidth);
        final boolean canFitWithOverflow = menuItemButtonWidth <= availableWidth - mOverflowButtonSize.getWidth();
        final boolean canFitNoOverflow = isLastItem && menuItemButtonWidth <= availableWidth;
        if (canFitWithOverflow || canFitNoOverflow) {
            setButtonTagAndClickListener(menuItemButton, menuItem);
            //menuItemButton.setTooltipText(menuItem.getTooltipText()); TODO
            mMainPanel.addView(menuItemButton);
            final ViewGroup.LayoutParams params = menuItemButton.getLayoutParams();
            params.width = menuItemButtonWidth;
            menuItemButton.setLayoutParams(params);
            availableWidth -= menuItemButtonWidth;
            remainingMenuItems.pop();
        } else {
            break;
        }
        isFirstItem = false;
    }
    if (!remainingMenuItems.isEmpty()) {
        mMainPanel.setPaddingRelative(0, 0, mOverflowButtonSize.getWidth(), 0);
    }
    mMainPanelSize = measure(mMainPanel);
    return remainingMenuItems;
}
 
Example 13
Source File: FloatingToolbar.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public List<MenuItem> layoutMainPanelItems(List<MenuItem> menuItems, final int toolbarWidth) {
    int availableWidth = toolbarWidth;
    final LinkedList<MenuItem> remainingMenuItems = new LinkedList<>(menuItems);
    /*final LinkedList<MenuItem> overflowMenuItems = new LinkedList<>();
    for (MenuItem menuItem : menuItems) {
        if (menuItem.requiresOverflow()) {
            overflowMenuItems.add(menuItem); TODO
        } else {
            remainingMenuItems.add(menuItem);
        }
    }
    remainingMenuItems.addAll(overflowMenuItems);*/
    mMainPanel.removeAllViews();
    mMainPanel.setPaddingRelative(0, 0, 0, 0);
    boolean isFirstItem = true;
    while (!remainingMenuItems.isEmpty()) {
        final MenuItem menuItem = remainingMenuItems.peek();
        /*if (!isFirstItem && menuItem.requiresOverflow()) {
            break;
        }*/
        final View menuItemButton = createMenuItemButton(mContext, menuItem, mIconTextSpacing);
        if (menuItemButton instanceof LinearLayout) {
            ((LinearLayout) menuItemButton).setGravity(Gravity.CENTER);
        }
        if (isFirstItem) {
            menuItemButton.setPaddingRelative((int) (1.5 * menuItemButton.getPaddingStart()), menuItemButton.getPaddingTop(), menuItemButton.getPaddingEnd(), menuItemButton.getPaddingBottom());
        }
        boolean isLastItem = remainingMenuItems.size() == 1;
        if (isLastItem) {
            menuItemButton.setPaddingRelative(menuItemButton.getPaddingStart(), menuItemButton.getPaddingTop(), (int) (1.5 * menuItemButton.getPaddingEnd()), menuItemButton.getPaddingBottom());
        }
        menuItemButton.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
        final int menuItemButtonWidth = Math.min(menuItemButton.getMeasuredWidth(), toolbarWidth);
        final boolean canFitWithOverflow = menuItemButtonWidth <= availableWidth - mOverflowButtonSize.getWidth();
        final boolean canFitNoOverflow = isLastItem && menuItemButtonWidth <= availableWidth;
        if (canFitWithOverflow || canFitNoOverflow) {
            setButtonTagAndClickListener(menuItemButton, menuItem);
            //menuItemButton.setTooltipText(menuItem.getTooltipText()); TODO
            mMainPanel.addView(menuItemButton);
            final ViewGroup.LayoutParams params = menuItemButton.getLayoutParams();
            params.width = menuItemButtonWidth;
            menuItemButton.setLayoutParams(params);
            availableWidth -= menuItemButtonWidth;
            remainingMenuItems.pop();
        } else {
            break;
        }
        isFirstItem = false;
    }
    if (!remainingMenuItems.isEmpty()) {
        mMainPanel.setPaddingRelative(0, 0, mOverflowButtonSize.getWidth(), 0);
    }
    mMainPanelSize = measure(mMainPanel);
    return remainingMenuItems;
}