Example usage for android.view Gravity CENTER_HORIZONTAL

List of usage examples for android.view Gravity CENTER_HORIZONTAL

Introduction

In this page you can find the example usage for android.view Gravity CENTER_HORIZONTAL.

Prototype

int CENTER_HORIZONTAL

To view the source code for android.view Gravity CENTER_HORIZONTAL.

Click Source Link

Document

Place object in the horizontal center of its container, not changing its size.

Usage

From source file:com.actionbarsherlock.internal.widget.ActionBarView.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int childCount = getChildCount();
    if (mIsCollapsable) {
        int visibleChildren = 0;
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);
            if (child.getVisibility() != GONE && !(child == mMenuView && mMenuView.getChildCount() == 0)) {
                visibleChildren++;/*  w w  w  .j a va  2 s.  co  m*/
            }
        }

        if (visibleChildren == 0) {
            // No size for an empty action bar when collapsable.
            setMeasuredDimension(0, 0);
            mIsCollapsed = true;
            return;
        }
    }
    mIsCollapsed = false;

    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    if (widthMode != MeasureSpec.EXACTLY) {
        throw new IllegalStateException(getClass().getSimpleName() + " can only be used "
                + "with android:layout_width=\"match_parent\" (or fill_parent)");
    }

    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    if (heightMode != MeasureSpec.AT_MOST) {
        throw new IllegalStateException(getClass().getSimpleName() + " can only be used "
                + "with android:layout_height=\"wrap_content\"");
    }

    int contentWidth = MeasureSpec.getSize(widthMeasureSpec);

    int maxHeight = mContentHeight > 0 ? mContentHeight : MeasureSpec.getSize(heightMeasureSpec);

    final int verticalPadding = getPaddingTop() + getPaddingBottom();
    final int paddingLeft = getPaddingLeft();
    final int paddingRight = getPaddingRight();
    final int height = maxHeight - verticalPadding;
    final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);

    int availableWidth = contentWidth - paddingLeft - paddingRight;
    int leftOfCenter = availableWidth / 2;
    int rightOfCenter = leftOfCenter;

    HomeView homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout;

    if (homeLayout.getVisibility() != GONE) {
        final ViewGroup.LayoutParams lp = homeLayout.getLayoutParams();
        int homeWidthSpec;
        if (lp.width < 0) {
            homeWidthSpec = MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST);
        } else {
            homeWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
        }
        homeLayout.measure(homeWidthSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
        final int homeWidth = homeLayout.getMeasuredWidth() + homeLayout.getLeftOffset();
        availableWidth = Math.max(0, availableWidth - homeWidth);
        leftOfCenter = Math.max(0, availableWidth - homeWidth);
    }

    if (mMenuView != null && mMenuView.getParent() == this) {
        availableWidth = measureChildView(mMenuView, availableWidth, childSpecHeight, 0);
        rightOfCenter = Math.max(0, rightOfCenter - mMenuView.getMeasuredWidth());
    }

    if (mIndeterminateProgressView != null && mIndeterminateProgressView.getVisibility() != GONE) {
        availableWidth = measureChildView(mIndeterminateProgressView, availableWidth, childSpecHeight, 0);
        rightOfCenter = Math.max(0, rightOfCenter - mIndeterminateProgressView.getMeasuredWidth());
    }

    final boolean showTitle = mTitleLayout != null && mTitleLayout.getVisibility() != GONE
            && (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0;

    if (mExpandedActionView == null) {
        switch (mNavigationMode) {
        case ActionBar.NAVIGATION_MODE_LIST:
            if (mListNavLayout != null) {
                final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding;
                availableWidth = Math.max(0, availableWidth - itemPaddingSize);
                leftOfCenter = Math.max(0, leftOfCenter - itemPaddingSize);
                mListNavLayout.measure(MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
                        MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
                final int listNavWidth = mListNavLayout.getMeasuredWidth();
                availableWidth = Math.max(0, availableWidth - listNavWidth);
                leftOfCenter = Math.max(0, leftOfCenter - listNavWidth);
            }
            break;
        case ActionBar.NAVIGATION_MODE_TABS:
            if (mTabScrollView != null) {
                final int itemPaddingSize = showTitle ? mItemPadding * 2 : mItemPadding;
                availableWidth = Math.max(0, availableWidth - itemPaddingSize);
                leftOfCenter = Math.max(0, leftOfCenter - itemPaddingSize);
                mTabScrollView.measure(MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
                        MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
                final int tabWidth = mTabScrollView.getMeasuredWidth();
                availableWidth = Math.max(0, availableWidth - tabWidth);
                leftOfCenter = Math.max(0, leftOfCenter - tabWidth);
            }
            break;
        }
    }

    View customView = null;
    if (mExpandedActionView != null) {
        customView = mExpandedActionView;
    } else if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomNavView != null) {
        customView = mCustomNavView;
    }

    if (customView != null) {
        final ViewGroup.LayoutParams lp = generateLayoutParams(customView.getLayoutParams());
        final ActionBar.LayoutParams ablp = lp instanceof ActionBar.LayoutParams ? (ActionBar.LayoutParams) lp
                : null;

        int horizontalMargin = 0;
        int verticalMargin = 0;
        if (ablp != null) {
            horizontalMargin = ablp.leftMargin + ablp.rightMargin;
            verticalMargin = ablp.topMargin + ablp.bottomMargin;
        }

        // If the action bar is wrapping to its content height, don't allow a custom
        // view to MATCH_PARENT.
        int customNavHeightMode;
        if (mContentHeight <= 0) {
            customNavHeightMode = MeasureSpec.AT_MOST;
        } else {
            customNavHeightMode = lp.height != LayoutParams.WRAP_CONTENT ? MeasureSpec.EXACTLY
                    : MeasureSpec.AT_MOST;
        }
        final int customNavHeight = Math.max(0,
                (lp.height >= 0 ? Math.min(lp.height, height) : height) - verticalMargin);

        final int customNavWidthMode = lp.width != LayoutParams.WRAP_CONTENT ? MeasureSpec.EXACTLY
                : MeasureSpec.AT_MOST;
        int customNavWidth = Math.max(0,
                (lp.width >= 0 ? Math.min(lp.width, availableWidth) : availableWidth) - horizontalMargin);
        final int hgrav = (ablp != null ? ablp.gravity : DEFAULT_CUSTOM_GRAVITY)
                & Gravity.HORIZONTAL_GRAVITY_MASK;

        // Centering a custom view is treated specially; we try to center within the whole
        // action bar rather than in the available space.
        if (hgrav == Gravity.CENTER_HORIZONTAL && lp.width == LayoutParams.MATCH_PARENT) {
            customNavWidth = Math.min(leftOfCenter, rightOfCenter) * 2;
        }

        customView.measure(MeasureSpec.makeMeasureSpec(customNavWidth, customNavWidthMode),
                MeasureSpec.makeMeasureSpec(customNavHeight, customNavHeightMode));
        availableWidth -= horizontalMargin + customView.getMeasuredWidth();
    }

    if (mExpandedActionView == null && showTitle) {
        availableWidth = measureChildView(mTitleLayout, availableWidth,
                MeasureSpec.makeMeasureSpec(mContentHeight, MeasureSpec.EXACTLY), 0);
        leftOfCenter = Math.max(0, leftOfCenter - mTitleLayout.getMeasuredWidth());
    }

    if (mContentHeight <= 0) {
        int measuredHeight = 0;
        for (int i = 0; i < childCount; i++) {
            View v = getChildAt(i);
            int paddedViewHeight = v.getMeasuredHeight() + verticalPadding;
            if (paddedViewHeight > measuredHeight) {
                measuredHeight = paddedViewHeight;
            }
        }
        setMeasuredDimension(contentWidth, measuredHeight);
    } else {
        setMeasuredDimension(contentWidth, maxHeight);
    }

    if (mContextView != null) {
        mContextView.setContentHeight(getMeasuredHeight());
    }

    if (mProgressView != null && mProgressView.getVisibility() != GONE) {
        mProgressView.measure(
                MeasureSpec.makeMeasureSpec(contentWidth - mProgressBarPadding * 2, MeasureSpec.EXACTLY),
                MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST));
    }
}

From source file:android.support.v7.internal.widget.ActionBarView.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int x = getPaddingLeft();
    final int y = getPaddingTop();
    final int contentHeight = b - t - getPaddingTop() - getPaddingBottom();

    if (contentHeight <= 0) {
        // Nothing to do if we can't see anything.
        return;/*from w  w  w. j a v  a  2 s. c o m*/
    }

    HomeView homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout;
    if (homeLayout.getVisibility() != GONE) {
        final int leftOffset = homeLayout.getLeftOffset();
        x += positionChild(homeLayout, x + leftOffset, y, contentHeight) + leftOffset;
    }

    if (mExpandedActionView == null) {
        final boolean showTitle = mTitleLayout != null && mTitleLayout.getVisibility() != GONE
                && (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0;
        if (showTitle) {
            x += positionChild(mTitleLayout, x, y, contentHeight);
        }

        switch (mNavigationMode) {
        case ActionBar.NAVIGATION_MODE_STANDARD:
            break;
        case ActionBar.NAVIGATION_MODE_LIST:
            if (mListNavLayout != null) {
                if (showTitle) {
                    x += mItemPadding;
                }
                x += positionChild(mListNavLayout, x, y, contentHeight) + mItemPadding;
            }
            break;
        case ActionBar.NAVIGATION_MODE_TABS:
            if (mTabScrollView != null) {
                if (showTitle) {
                    x += mItemPadding;
                }
                x += positionChild(mTabScrollView, x, y, contentHeight) + mItemPadding;
            }
            break;
        }
    }

    int menuLeft = r - l - getPaddingRight();
    if (mMenuView != null && mMenuView.getParent() == this) {
        positionChildInverse(mMenuView, menuLeft, y, contentHeight);
        menuLeft -= mMenuView.getMeasuredWidth();
    }

    if (mIndeterminateProgressView != null && mIndeterminateProgressView.getVisibility() != GONE) {
        positionChildInverse(mIndeterminateProgressView, menuLeft, y, contentHeight);
        menuLeft -= mIndeterminateProgressView.getMeasuredWidth();
    }

    View customView = null;
    if (mExpandedActionView != null) {
        customView = mExpandedActionView;
    } else if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomNavView != null) {
        customView = mCustomNavView;
    }
    if (customView != null) {
        ViewGroup.LayoutParams lp = customView.getLayoutParams();
        final ActionBar.LayoutParams ablp = lp instanceof ActionBar.LayoutParams ? (ActionBar.LayoutParams) lp
                : null;

        final int gravity = ablp != null ? ablp.gravity : DEFAULT_CUSTOM_GRAVITY;
        final int navWidth = customView.getMeasuredWidth();

        int topMargin = 0;
        int bottomMargin = 0;
        if (ablp != null) {
            x += ablp.leftMargin;
            menuLeft -= ablp.rightMargin;
            topMargin = ablp.topMargin;
            bottomMargin = ablp.bottomMargin;
        }

        int hgravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
        // See if we actually have room to truly center; if not push against left or right.
        if (hgravity == Gravity.CENTER_HORIZONTAL) {
            final int centeredLeft = (getWidth() - navWidth) / 2;
            if (centeredLeft < x) {
                hgravity = Gravity.LEFT;
            } else if (centeredLeft + navWidth > menuLeft) {
                hgravity = Gravity.RIGHT;
            }
        } else if (gravity == -1) {
            hgravity = Gravity.LEFT;
        }

        int xpos = 0;
        switch (hgravity) {
        case Gravity.CENTER_HORIZONTAL:
            xpos = (getWidth() - navWidth) / 2;
            break;
        case Gravity.LEFT:
            xpos = x;
            break;
        case Gravity.RIGHT:
            xpos = menuLeft - navWidth;
            break;
        }

        int vgravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

        if (gravity == -1) {
            vgravity = Gravity.CENTER_VERTICAL;
        }

        int ypos = 0;
        switch (vgravity) {
        case Gravity.CENTER_VERTICAL:
            final int paddedTop = getPaddingTop();
            final int paddedBottom = getHeight() - getPaddingBottom();
            ypos = ((paddedBottom - paddedTop) - customView.getMeasuredHeight()) / 2;
            break;
        case Gravity.TOP:
            ypos = getPaddingTop() + topMargin;
            break;
        case Gravity.BOTTOM:
            ypos = getHeight() - getPaddingBottom() - customView.getMeasuredHeight() - bottomMargin;
            break;
        }
        final int customWidth = customView.getMeasuredWidth();
        customView.layout(xpos, ypos, xpos + customWidth, ypos + customView.getMeasuredHeight());
        x += customWidth;
    }

    if (mProgressView != null) {
        mProgressView.bringToFront();
        final int halfProgressHeight = mProgressView.getMeasuredHeight() / 2;
        mProgressView.layout(mProgressBarPadding, -halfProgressHeight,
                mProgressBarPadding + mProgressView.getMeasuredWidth(), halfProgressHeight);
    }
}

From source file:de.mrapp.android.bottomsheet.BottomSheet.java

/**
 * Creates and returns the layout params, which should be used to show the bottom sheet's root
 * view./*from w  w w . j a v  a 2s .c  o  m*/
 *
 * @return The layout params, which have been created, as an instance of the class {@link
 * android.widget.FrameLayout.LayoutParams }
 */
private FrameLayout.LayoutParams createRootViewLayoutParams() {
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
    return layoutParams;
}

From source file:chao.widget.tablayout.TabLayout.java

private void applyModeAndGravity() {
    int paddingStart = 0;
    if (mMode == MODE_SCROLLABLE) {
        // If we're scrollable, or fixed at start, inset using padding
        paddingStart = Math.max(0, mContentInsetStart - mTabPaddingStart);
    }/*from www . jav a2s .  c  om*/
    ViewCompat.setPaddingRelative(mTabStrip, paddingStart, 0, 0, 0);

    switch (mMode) {
    case MODE_FIXED:
    case MODE_FIXED_COMMON:
        mTabStrip.setGravity(Gravity.CENTER_HORIZONTAL);
        break;
    case MODE_SCROLLABLE:
        mTabStrip.setGravity(GravityCompat.START);
        break;
    }

    updateTabViews(true);
}

From source file:cm.aptoide.pt.MainActivity.java

protected void addStore(String uri_str, String username, String password) {

    if (uri_str.contains("http//")) {
        uri_str = uri_str.replaceFirst("http//", "http://");
    }/* w w w  .  j a v  a2 s  . c  om*/

    if (uri_str.length() != 0 && uri_str.charAt(uri_str.length() - 1) != '/') {
        uri_str = uri_str + '/';
        Log.d("Aptoide-ManageRepo", "repo uri: " + uri_str);
    }
    if (!uri_str.startsWith("http://")) {
        uri_str = "http://" + uri_str;
        Log.d("Aptoide-ManageRepo", "repo uri: " + uri_str);
    }
    if (username != null && username.contains("@")) {
        try {
            password = Algorithms.computeSHA1sum(password);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    NetworkUtils utils = new NetworkUtils();
    final int response = utils.checkServerConnection(uri_str, username, password);
    final String uri = uri_str;
    switch (response) {
    case 0:
        service.addStore(db, uri, username, password);
        break;
    case 401:
        runOnUiThread(new Runnable() {

            @Override
            public void run() {

                showAddStoreCredentialsDialog(uri);
            }
        });

        break;
    case 404:
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Toast toast = Toast.makeText(mContext, mContext.getString(R.string.verify_store),
                        Toast.LENGTH_SHORT);
                toast.show();
                showAddStoreDialog();
            }
        });
        break;
    case -1:
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Toast toast = Toast.makeText(mContext, mContext.getString(R.string.an_error_check_net),
                        Toast.LENGTH_SHORT);
                toast.show();
                showAddStoreDialog();
            }
        });
        break;
    default:
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Toast toast = Toast.makeText(mContext,
                        mContext.getString(R.string.error_occured) + " " + response, Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 30);
                toast.show();
                showAddStoreDialog();
            }
        });
        break;
    }

}

From source file:chao.widget.tablayout.TabLayout.java

private void updateTabViews(final boolean requestLayout) {
    for (int i = 0; i < mTabStrip.getChildCount(); i++) {
        TabView child = (TabView) mTabStrip.getChildAt(i);
        child.setMinimumWidth(getTabMinWidth());
        child.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);

        LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams();
        updateTabViewLayoutParams(lp);//from w w  w  .  j  a  v  a 2s. com
        if (mMode == MODE_FIXED_COMMON) {
            child.setGravity(GravityCompat.START);
            lp.width = LinearLayout.LayoutParams.WRAP_CONTENT;
            if (i == mTabStrip.getChildCount() - 1) {
                lp.weight = 0;
            }
        }
        if (requestLayout) {
            child.requestLayout();
        }
    }
}

From source file:android.support.design.widget.CoordinatorLayout.java

/**
 * Lay out a child view with respect to a keyline.
 *
 * <p>The keyline represents a horizontal offset from the unpadded starting edge of
 * the CoordinatorLayout. The child's gravity will affect how it is positioned with
 * respect to the keyline.</p>/*from w  w w.  jav  a  2  s . co m*/
 *
 * @param child child to lay out
 * @param keyline offset from the starting edge in pixels of the keyline to align with
 * @param layoutDirection ViewCompat constant for layout direction
 */
private void layoutChildWithKeyline(View child, int keyline, int layoutDirection) {
    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    final int absGravity = GravityCompat.getAbsoluteGravity(resolveKeylineGravity(lp.gravity), layoutDirection);

    final int hgrav = absGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    final int vgrav = absGravity & Gravity.VERTICAL_GRAVITY_MASK;
    final int width = getWidth();
    final int height = getHeight();
    final int childWidth = child.getMeasuredWidth();
    final int childHeight = child.getMeasuredHeight();

    if (layoutDirection == ViewCompat.LAYOUT_DIRECTION_RTL) {
        keyline = width - keyline;
    }

    int left = getKeyline(keyline) - childWidth;
    int top = 0;

    switch (hgrav) {
    default:
    case Gravity.LEFT:
        // Nothing to do.
        break;
    case Gravity.RIGHT:
        left += childWidth;
        break;
    case Gravity.CENTER_HORIZONTAL:
        left += childWidth / 2;
        break;
    }

    switch (vgrav) {
    default:
    case Gravity.TOP:
        // Do nothing, we're already in position.
        break;
    case Gravity.BOTTOM:
        top += childHeight;
        break;
    case Gravity.CENTER_VERTICAL:
        top += childHeight / 2;
        break;
    }

    // Obey margins and padding
    left = Math.max(getPaddingLeft() + lp.leftMargin,
            Math.min(left, width - getPaddingRight() - childWidth - lp.rightMargin));
    top = Math.max(getPaddingTop() + lp.topMargin,
            Math.min(top, height - getPaddingBottom() - childHeight - lp.bottomMargin));

    child.layout(left, top, left + childWidth, top + childHeight);
}

From source file:com.mishiranu.dashchan.ui.navigator.NavigatorActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void showThemeDialog() {
    final int checkedItem = Arrays.asList(Preferences.VALUES_THEME).indexOf(Preferences.getTheme());
    Resources resources = getResources();
    float density = ResourceUtils.obtainDensity(resources);
    ScrollView scrollView = new ScrollView(this);
    LinearLayout outer = new LinearLayout(this);
    outer.setOrientation(LinearLayout.VERTICAL);
    int outerPadding = (int) (16f * density);
    outer.setPadding(outerPadding, outerPadding, outerPadding, outerPadding);
    scrollView.addView(outer, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.action_change_theme)
            .setView(scrollView).setNegativeButton(android.R.string.cancel, null).create();
    View.OnClickListener listener = v -> {
        int index = (int) v.getTag();
        if (index != checkedItem) {
            Preferences.setTheme(Preferences.VALUES_THEME[index]);
            recreate();//from   www  .j  a  v a 2  s. c o  m
        }
        dialog.dismiss();
    };
    int circleSize = (int) (56f * density);
    int itemPadding = (int) (12f * density);
    LinearLayout inner = null;
    for (int i = 0; i < Preferences.ENTRIES_THEME.length; i++) {
        if (i % 3 == 0) {
            inner = new LinearLayout(this);
            inner.setOrientation(LinearLayout.HORIZONTAL);
            outer.addView(inner, LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
        }
        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.setGravity(Gravity.CENTER);
        layout.setBackgroundResource(
                ResourceUtils.getResourceId(this, android.R.attr.selectableItemBackground, 0));
        layout.setPadding(0, itemPadding, 0, itemPadding);
        layout.setOnClickListener(listener);
        layout.setTag(i);
        inner.addView(layout, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
        View view = new View(this);
        int colorBackgroundAttr = Preferences.VALUES_THEME_COLORS[i][0];
        int colorPrimaryAttr = Preferences.VALUES_THEME_COLORS[i][1];
        int colorAccentAttr = Preferences.VALUES_THEME_COLORS[i][2];
        Resources.Theme theme = getResources().newTheme();
        theme.applyStyle(Preferences.VALUES_THEME_IDS[i], true);
        TypedArray typedArray = theme
                .obtainStyledAttributes(new int[] { colorBackgroundAttr, colorPrimaryAttr, colorAccentAttr });
        view.setBackground(new ThemeChoiceDrawable(typedArray.getColor(0, 0), typedArray.getColor(1, 0),
                typedArray.getColor(2, 0)));
        typedArray.recycle();
        if (C.API_LOLLIPOP) {
            view.setElevation(6f * density);
        }
        layout.addView(view, circleSize, circleSize);
        TextView textView = new TextView(this, null, android.R.attr.textAppearanceListItem);
        textView.setSingleLine(true);
        textView.setEllipsize(TextUtils.TruncateAt.END);
        textView.setText(Preferences.ENTRIES_THEME[i]);
        if (C.API_LOLLIPOP) {
            textView.setAllCaps(true);
            textView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12f);
        } else {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f);
        }
        textView.setGravity(Gravity.CENTER_HORIZONTAL);
        textView.setPadding(0, (int) (8f * density), 0, 0);
        layout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        if (i + 1 == Preferences.ENTRIES_THEME.length && Preferences.ENTRIES_THEME.length % 3 != 0) {
            if (Preferences.ENTRIES_THEME.length % 3 == 1) {
                inner.addView(new View(this), 0,
                        new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f));
            }
            inner.addView(new View(this),
                    new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f));
        }
    }
    dialog.show();
}

From source file:android.support.design.widget.RaeTabLayout.java

private void applyModeAndGravity() {
    int paddingStart = 0;
    if (mMode == MODE_SCROLLABLE) {
        // If we're scrollable, or fixed at start, inset using padding
        paddingStart = Math.max(0, mContentInsetStart - mTabPaddingStart);
    }/*from  ww  w  . j a v a2 s.  co  m*/
    ViewCompat.setPaddingRelative(mTabStrip, paddingStart, 0, 0, 0);

    switch (mMode) {
    case MODE_FIXED:
        mTabStrip.setGravity(Gravity.CENTER_HORIZONTAL);
        break;
    case MODE_SCROLLABLE:
        mTabStrip.setGravity(GravityCompat.START);
        break;
    }

    updateTabViews(true);
}

From source file:org.ednovo.goorusearchwidget.SearchResults_resource.java

public LinearLayout createResourceEmptyView() {

    LinearLayout scrollChild = new LinearLayout(this);
    scrollChild.setPadding(10, 0, 10, 0);
    resourcelayout = LayoutInflater.from(this).inflate(R.layout.resource_view, null);
    TextView title = (TextView) resourcelayout.findViewById(R.id.textViewTitle);
    title.setText("Sorry! No Results Found");
    title.setTextColor(getResources().getColor(R.color.Grey));
    title.setPadding(50, 50, 0, 10);/* w w w . j ava2 s  .co  m*/
    title.setTextSize(25);

    scrollChild.addView(resourcelayout, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.MATCH_PARENT));
    scrollChild.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    return scrollChild;
}