Example usage for android.view Gravity CENTER_VERTICAL

List of usage examples for android.view Gravity CENTER_VERTICAL

Introduction

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

Prototype

int CENTER_VERTICAL

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

Click Source Link

Document

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

Usage

From source file:com.luckybuy.ctrls.SlidingTabLayout.java

public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);//from w  w  w.  j  a v a  2s.c om

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);

    mTabStrip = new SlidingTabStrip(context);
    mTabStrip.setOrientation(LinearLayout.HORIZONTAL);
    mTabStrip.setGravity(Gravity.CENTER_VERTICAL);
    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    mTabTextSize = DisplayUtils.sp2px(getContext(), TAB_VIEW_TEXT_SIZE_SP);
    mTabTextPadding = TAB_VIEW_PADDING_DIPS;
    mTabLayoutEven = true;
    mTabColorStateList = -1;
}

From source file:com.yaozu.object.widget.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setFillViewport(true);/*ww  w.  java  2  s .c o  m*/
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    tabsContainer.setGravity(Gravity.CENTER_VERTICAL); // ?
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    //scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    mScrollOffset = dm.widthPixels / 2;
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);

    // add by hangl begin
    tabPaddingVertical = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPaddingVertical, dm);
    // add by hangl end

    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabTextSize, dm); // change sp to dp

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    a.recycle();
    // get custom attrs

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
    tabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_tabTextColor, tabTextColor);
    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    tabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_tabTextSize, tabTextSize);

    // add by hangl begin
    tabTextColorNormal = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTextNormalColor, tabTextColorNormal);
    tabTextColorSelected = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTextSelectedColor,
            tabTextColorSelected);
    tabPaddingVertical = a.getDimensionPixelOffset(R.styleable.PagerSlidingTabStrip_pstsTabPaddingVertical,
            tabPaddingVertical);
    expandViewWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsExpandViewWidth,
            expandViewWidth);
    // add by hangl end

    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    mScrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, mScrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    Paint dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:org.telegram.ui.Cells.SharedDocumentCell.java

public SharedDocumentCell(Context context) {
    super(context);

    if (paint == null) {
        paint = new Paint();
        paint.setColor(ContextCompat.getColor(context, R.color.divider));
        paint.setStrokeWidth(1);//from  w w w.java2  s  .c o m
    }

    TAG = MediaController.getInstance().generateObserverTag();

    placeholderImabeView = new ImageView(context);
    addView(placeholderImabeView,
            LayoutHelper.createFrame(40, 40,
                    (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP,
                    LocaleController.isRTL ? 0 : 12, 8, LocaleController.isRTL ? 12 : 0, 0));

    extTextView = new TextView(context);
    extTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text_inverse));
    extTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    extTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    extTextView.setLines(1);
    extTextView.setMaxLines(1);
    extTextView.setSingleLine(true);
    extTextView.setGravity(Gravity.CENTER);
    extTextView.setEllipsize(TextUtils.TruncateAt.END);
    addView(extTextView,
            LayoutHelper.createFrame(32, LayoutHelper.WRAP_CONTENT,
                    (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP,
                    LocaleController.isRTL ? 0 : 16, 22, LocaleController.isRTL ? 16 : 0, 0));

    thumbImageView = new BackupImageView(context);
    addView(thumbImageView,
            LayoutHelper.createFrame(40, 40,
                    (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP,
                    LocaleController.isRTL ? 0 : 12, 8, LocaleController.isRTL ? 12 : 0, 0));
    thumbImageView.getImageReceiver().setDelegate(new ImageReceiver.ImageReceiverDelegate() {
        @Override
        public void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb) {
            extTextView.setVisibility(set ? INVISIBLE : VISIBLE);
            placeholderImabeView.setVisibility(set ? INVISIBLE : VISIBLE);
        }
    });

    nameTextView = new TextView(context);
    nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    nameTextView.setLines(1);
    nameTextView.setMaxLines(1);
    nameTextView.setSingleLine(true);
    nameTextView.setEllipsize(TextUtils.TruncateAt.END);
    nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
    addView(nameTextView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT,
                    (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP,
                    LocaleController.isRTL ? 8 : 72, 5, LocaleController.isRTL ? 72 : 8, 0));

    statusImageView = new ImageView(context);
    statusImageView.setVisibility(INVISIBLE);
    addView(statusImageView,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                    (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP,
                    LocaleController.isRTL ? 8 : 72, 35, LocaleController.isRTL ? 72 : 8, 0));

    dateTextView = new TextView(context);
    dateTextView.setTextColor(ContextCompat.getColor(context, R.color.secondary_text));
    dateTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    dateTextView.setLines(1);
    dateTextView.setMaxLines(1);
    dateTextView.setSingleLine(true);
    dateTextView.setEllipsize(TextUtils.TruncateAt.END);
    dateTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
    addView(dateTextView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT,
                    (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP,
                    LocaleController.isRTL ? 8 : 72, 30, LocaleController.isRTL ? 72 : 8, 0));

    progressView = new LineProgressView(context);
    addView(progressView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 2,
                    (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP,
                    LocaleController.isRTL ? 0 : 72, 54, LocaleController.isRTL ? 72 : 0, 0));

    checkBox = new CheckBox(context, R.drawable.round_check2);
    checkBox.setVisibility(INVISIBLE);
    addView(checkBox,
            LayoutHelper.createFrame(22, 22,
                    (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP,
                    LocaleController.isRTL ? 0 : 34, 30, LocaleController.isRTL ? 34 : 0, 0));
}

From source file:free.yhc.netmbuddy.YTSearchActivity.java

private void preparePageButtons() {
    mPageBtnHolder = new Button[Policy.YTSEARCH_NR_PAGE_INDEX_BUTTONS];
    mPageBtnLPHolder = new LinearLayout.LayoutParams(
            getResources().getDimensionPixelSize(R.dimen.ytsearch_idxbtn_width),
            getResources().getDimensionPixelSize(R.dimen.ytsearch_idxbtn_height));
    mPageBtnLPHolder.gravity = Gravity.CENTER_VERTICAL;
    for (int i = 0; i < mPageBtnHolder.length; i++) {
        mPageBtnHolder[i] = new Button(this);
        mPageBtnHolder[i].setTag(i);/*w  w  w.  j av a2 s.c o  m*/
        mPageBtnHolder[i].setOnClickListener(mPageOnClick);
    }
}

From source file:com.ayoview.sample.textview.badge.ViewsFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.counter: {
        counterBadge.incrementBadgeCount(1);
        break;/*w  ww  .  j  av a  2 s  . c o m*/
    }

    case R.id.gravity: {
        gravityBadge.incrementBadgeCount(1);
        Log.d(getClass().getName(), String.valueOf(gravityBadge.getBadgeCount() % 9));
        if (gravityBadge.getBadgeCount() % 9 == 0) {
            gravityBadge.setBadgeGravity(Gravity.LEFT | Gravity.TOP);
        } else if (gravityBadge.getBadgeCount() % 9 == 1) {
            gravityBadge.setBadgeGravity(Gravity.RIGHT | Gravity.BOTTOM);
        } else if (gravityBadge.getBadgeCount() % 9 == 2) {
            gravityBadge.setBadgeGravity(Gravity.LEFT | Gravity.BOTTOM);
        } else if (gravityBadge.getBadgeCount() % 9 == 3) {
            gravityBadge.setBadgeGravity(Gravity.RIGHT | Gravity.TOP);
        } else if (gravityBadge.getBadgeCount() % 9 == 4) {
            gravityBadge.setBadgeGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
        } else if (gravityBadge.getBadgeCount() % 9 == 5) {
            gravityBadge.setBadgeGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
        } else if (gravityBadge.getBadgeCount() % 9 == 6) {
            gravityBadge.setBadgeGravity(Gravity.CENTER);
        } else if (gravityBadge.getBadgeCount() % 9 == 7) {
            gravityBadge.setBadgeGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
        } else if (gravityBadge.getBadgeCount() % 9 == 8) {
            gravityBadge.setBadgeGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
        }
        break;
    }
    case R.id.visibility: {
        visibilityBadgeView
                .setVisibility(visibilityBadgeView.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
        break;
    }

    default:
        break;
    }

}

From source file:com.android.settings.profiles.ProfilesSettings.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    // We don't call super.onActivityCreated() here, since it assumes we already set up
    // Preference (probably in onCreate()), while ProfilesSettings exceptionally set it up in
    // this method.
    // On/off switch
    Activity activity = getActivity();/*from w  ww .j av a 2  s  .c  om*/
    //Switch
    mActionBarSwitch = new Switch(activity);

    if (activity instanceof PreferenceActivity) {
        PreferenceActivity preferenceActivity = (PreferenceActivity) activity;
        if (preferenceActivity.onIsHidingHeaders() || !preferenceActivity.onIsMultiPane()) {
            final int padding = activity.getResources()
                    .getDimensionPixelSize(R.dimen.action_bar_switch_padding);
            mActionBarSwitch.setPaddingRelative(0, 0, padding, 0);
            activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
                    ActionBar.DISPLAY_SHOW_CUSTOM);
            activity.getActionBar().setCustomView(mActionBarSwitch,
                    new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
                            ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END));
        }
    }

    mProfileEnabler = new ProfileEnabler(activity, mActionBarSwitch);

    // After confirming PreferenceScreen is available, we call super.
    super.onActivityCreated(savedInstanceState);
}

From source file:net.evecom.androidecssp.activity.event.EventAddActivity.java

/**
 * /*from   w  ww  .ja  v  a 2  s .  c o m*/
 *  gallery
 * 
 * @author Mars zhang
 * @created 2015-11-19 10:55:25
 */
private void initGallery() {
    mGallery = (GalleryFlow) findViewById(R.id.event_add_gallery_flow);
    mGallery.setBackgroundColor(Color.parseColor("#ffffff")); // 
    mGallery.setSpacing(90);// 
    mGallery.setMaxRotationAngle(20);// 
    mGallery.setFadingEdgeLength(10); // 
    mGallery.setGravity(Gravity.CENTER_VERTICAL); // 
    mGallery.setAdapter(new GalleryAdapter());
    mGallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(getApplicationContext(), AfnailPictureActivity.class);
            BaseActivity.pushObjData("filebean", filebeans.get(position), intent);
            startActivityForResult(intent, R.layout.afnail_picture_activity);
        }
    });
}

From source file:sudosaints.com.testsample.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//from   ww w .  j  a v a2 s . c om
 */
protected TextView createDefaultTabView(Context context) {
    RobotoTextView textView = new RobotoTextView(context);
    Typeface typeface = RobotoTypefaceManager.obtainTypeface(context,
            RobotoTypefaceManager.Typeface.ROBOTO_CONDENSED_BOLD);
    RobotoTextViewUtils.setTypeface(textView, typeface);
    textView.setGravity(Gravity.CENTER_VERTICAL);

    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:com.lamcreations.scaffold.common.views.CollapsingToolbarTabLayout.java

private CollapsingTextHelper getCollapsingTextHelper() {
    if (mCollapsingTextHelper == null) {
        mCollapsingTextHelper = new CollapsingTextHelper(this);
        mCollapsingTextHelper.setCollapsedTextVerticalGravity(Gravity.CENTER_VERTICAL);
        mCollapsingTextHelper.setExpandedTextVerticalGravity(Gravity.BOTTOM);
        mCollapsingTextHelper//  ww  w .j  a v a2 s.  c  o m
                .setTextSizeInterpolator(CollapsingTextHelper.AnimationUtils.DECELERATE_INTERPOLATOR);
    }
    return mCollapsingTextHelper;
}

From source file:com.justplay1.shoppist.shared.base.adapters.BaseGroupSwipeableItemAdapter.java

@Override
public void onSetChildItemSwipeBackground(CVH holder, int groupPosition, int childPosition, int type) {
    int bgResId = R.drawable.bg_swipe_item_neutral;
    LayerDrawable drawable = (LayerDrawable) ContextCompat.getDrawable(context, bgResId);
    switch (type) {
    case SwipeableItemConstants.DRAWABLE_SWIPE_LEFT_BACKGROUND:
        switch (getLeftSwipeActionType()) {
        case SwipeActionType.MOVE_ITEM:
            if (getChildItem(groupPosition, childPosition).getStatus()) {
                bgResId = getMoveToStatusNotDoneIcon();
            } else {
                bgResId = getMoveToStatusDoneIcon();
            }//from w  ww . j  ava  2s . c o  m
            break;
        case SwipeActionType.DELETE_ITEM:
            bgResId = R.drawable.bg_swipe_item_delete_action;
            break;
        case SwipeActionType.EDIT_ITEM:
            bgResId = R.drawable.bg_swipe_item_edit_action;
            break;
        }
        drawable = (LayerDrawable) ContextCompat.getDrawable(context, bgResId);
        ((BitmapDrawable) drawable.findDrawableByLayerId(R.id.image))
                .setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
        break;
    case SwipeableItemConstants.DRAWABLE_SWIPE_RIGHT_BACKGROUND:
        bgResId = R.drawable.bg_swipe_item_move_to_cart_action;
        switch (getRightSwipeActionType()) {
        case SwipeActionType.MOVE_ITEM:
            if (getChildItem(groupPosition, childPosition).getStatus()) {
                bgResId = getMoveToStatusNotDoneIcon();
            } else {
                bgResId = getMoveToStatusDoneIcon();
            }
            break;
        case SwipeActionType.DELETE_ITEM:
            bgResId = R.drawable.bg_swipe_item_delete_action;
            break;
        case SwipeActionType.EDIT_ITEM:
            bgResId = R.drawable.bg_swipe_item_edit_action;
            break;
        }
        drawable = (LayerDrawable) ContextCompat.getDrawable(context, bgResId);
        ((BitmapDrawable) drawable.findDrawableByLayerId(R.id.image))
                .setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
        break;
    }
    DrawableUtils.setViewDrawable(holder.itemView, drawable);
}