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:org.telegram.ui.Cells.ArchivedStickerSetCell.java

public ArchivedStickerSetCell(Context context, boolean needCheckBox) {
    super(context);

    setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
    setElevation(AndroidUtilities.dp(2));

    if (paint == null) {
        paint = new Paint();
        paint.setColor(ContextCompat.getColor(context, R.color.divider));
    }//  www .j  a v  a2 s  . co  m

    textView = new TextView(context);
    textView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    textView.setLines(1);
    textView.setMaxLines(1);
    textView.setSingleLine(true);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    addView(textView,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                    LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, LocaleController.isRTL ? 40 : 71, 10,
                    LocaleController.isRTL ? 71 : 40, 0));

    valueTextView = new TextView(context);
    //valueTextView.setTextColor(0xff8a8a8a);
    valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    valueTextView.setLines(1);
    valueTextView.setMaxLines(1);
    valueTextView.setSingleLine(true);
    valueTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    addView(valueTextView,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                    LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, LocaleController.isRTL ? 40 : 71, 35,
                    LocaleController.isRTL ? 71 : 40, 0));

    imageView = new BackupImageView(context);
    imageView.setAspectFit(true);
    addView(imageView,
            LayoutHelper.createFrame(48, 48,
                    (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP,
                    LocaleController.isRTL ? 0 : 12, 8, LocaleController.isRTL ? 12 : 0, 0));

    if (needCheckBox) {
        checkBox = new Switch(context);
        checkBox.setDuplicateParentStateEnabled(false);
        checkBox.setFocusable(false);
        checkBox.setFocusableInTouchMode(false);
        addView(checkBox,
                LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                        (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL, 14,
                        0, 14, 0));
    }
}

From source file:com.facebook.notifications.internal.content.TextContent.java

@Override
public void applyTo(@NonNull View view) {
    if (view instanceof TextView) {
        TextView textView = (TextView) view;

        textView.setText(getText());/*from  ww w.  ja  va2  s.co  m*/
        textView.setTextColor(getTextColor());

        Typeface typeface = FontUtilities.parseFont(getTypeface());
        typeface = typeface != null ? typeface : Typeface.DEFAULT;

        textView.setTypeface(typeface);
        textView.setTextSize(getTypefaceSize());

        switch (getTextAlignment()) {
        case Left:
            textView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
            break;

        case Center:
            textView.setGravity(Gravity.CENTER);
            break;

        case Right:
            textView.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
            break;
        }
    }
}

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

public UserCell(Context context, int padding, int checkbox, boolean admin) {
    super(context);

    setElevation(AndroidUtilities.dp(2));
    setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));

    avatarDrawable = new AvatarDrawable();

    avatarImageView = new BackupImageView(context);
    avatarImageView.setRoundRadius(AndroidUtilities.dp(24));
    addView(avatarImageView,/* w ww .  j av  a2  s  .  co m*/
            LayoutHelper.createFrame(48, 48,
                    (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP,
                    LocaleController.isRTL ? 0 : 7 + padding, 8, LocaleController.isRTL ? 7 + padding : 0, 0));

    nameTextView = new SimpleTextView(context);
    nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    nameTextView.setTextSize(17);
    nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    addView(nameTextView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 20,
                    (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP,
                    LocaleController.isRTL ? 28 + (checkbox == 2 ? 18 : 0) : (68 + padding), 11.5f,
                    LocaleController.isRTL ? (68 + padding) : 28 + (checkbox == 2 ? 18 : 0), 0));

    statusTextView = new SimpleTextView(context);
    statusTextView.setTextSize(14);
    statusTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    addView(statusTextView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 20,
                    (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP,
                    LocaleController.isRTL ? 28 : (68 + padding), 34.5f,
                    LocaleController.isRTL ? (68 + padding) : 28, 0));

    imageView = new ImageView(context);
    imageView.setScaleType(ImageView.ScaleType.CENTER);
    imageView.setVisibility(GONE);
    addView(imageView,
            LayoutHelper.createFrame(LayoutParams.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                    (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL,
                    LocaleController.isRTL ? 0 : 16, 0, LocaleController.isRTL ? 16 : 0, 0));

    if (checkbox == 2) {
        checkBoxBig = new CheckBoxSquare(context);
        addView(checkBoxBig,
                LayoutHelper.createFrame(18, 18,
                        (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL,
                        LocaleController.isRTL ? 19 : 0, 0, LocaleController.isRTL ? 0 : 19, 0));
    } else if (checkbox == 1) {
        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 : 37 + padding, 38, LocaleController.isRTL ? 37 + padding : 0, 0));
    }

    if (admin) {
        adminImage = new ImageView(context);
        addView(adminImage,
                LayoutHelper.createFrame(16, 16,
                        (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP,
                        LocaleController.isRTL ? 24 : 0, 13.5f, LocaleController.isRTL ? 0 : 24, 0));
    }
}

From source file:com.iStudy.Study.Renren.View.RenrenDialog.java

private void setUpTitle() {
    Drawable icon = getContext().getResources().getDrawable(R.drawable.renren_sdk_android_title_logo);
    title = new TextView(getContext());
    title.setText("");
    title.setTextColor(Color.WHITE);
    title.setGravity(Gravity.CENTER_VERTICAL);
    title.setTypeface(Typeface.DEFAULT_BOLD);
    title.setBackgroundColor(RENREN_BLUE);
    title.setBackgroundResource(R.drawable.renren_sdk_android_title_bg);
    title.setCompoundDrawablePadding(6);
    title.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
    content.addView(title);//from w ww.j a va 2  s.  c o  m
}

From source file:com.trimph.toprand.trimphrxandroid.trimph.ui.main.news.view.PagerSlidingTabStrip.java

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

    setFillViewport(true);/*from  w w w.j  av  a 2  s.c om*/
    setWillNotDraw(false);

    tabsContainer = new RadioGroup(context);

    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setGravity(Gravity.CENTER_VERTICAL);
    removeAllViews();
    addView(tabsContainer, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    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);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

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

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(1, tabTextColor);

    a.recycle();

    // get custom attrs

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    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);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    tabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTextSize, tabTextSize);
    tabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTextColor, tabTextColor);

    a.recycle();

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

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

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

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

From source file:com.kinvey.sample.kitchensink.account.LoginFragment.java

@Override
public void onClick(View v) {
    if (v == login) {

        if (implicit.isChecked()) {
            ((KitchenSinkApplication) getSherlockActivity().getApplicationContext()).getClient().user()
                    .login(new KinveyUserCallback() {
                        @Override
                        public void onSuccess(User result) {
                            if (getSherlockActivity() == null) {
                                return;
                            }//w  w  w .j  av a2  s .  co m
                            CharSequence text = "Logged in " + result.get("username") + ".";
                            Toast.makeText(getSherlockActivity().getApplicationContext(), text,
                                    Toast.LENGTH_LONG).show();
                            loggedIn();
                        }

                        @Override
                        public void onFailure(Throwable error) {
                            if (getSherlockActivity() == null) {
                                return;
                            }
                            CharSequence text = "Something went wrong -> " + error;
                            Toast toast = Toast.makeText(getSherlockActivity().getApplicationContext(), text,
                                    Toast.LENGTH_LONG);
                            toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                            toast.show();
                        }

                    });

        } else {
            ((KitchenSinkApplication) getSherlockActivity().getApplicationContext()).getClient().user().login(
                    username.getText().toString(), password.getText().toString(), new KinveyUserCallback() {
                        @Override
                        public void onSuccess(User result) {
                            if (getSherlockActivity() == null) {
                                return;
                            }
                            CharSequence text = "Logged in " + result.get("username") + ".";
                            Toast.makeText(getSherlockActivity().getApplicationContext(), text,
                                    Toast.LENGTH_LONG).show();
                            loggedIn();
                        }

                        public void onFailure(Throwable t) {
                            if (getSherlockActivity() == null) {
                                return;
                            }
                            CharSequence text = "Something went wrong -> " + t;
                            Toast toast = Toast.makeText(getSherlockActivity().getApplicationContext(), text,
                                    Toast.LENGTH_LONG);
                            toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                            toast.show();
                        }
                    });
        }

    }
}

From source file:com.jaredrummler.materialspinner.MaterialSpinner.java

private void init(Context context, AttributeSet attrs) {
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaterialSpinner);
    int defaultColor = getTextColors().getDefaultColor();
    backgroundColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_background_color, Color.WHITE);
    textColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_text_color, defaultColor);
    arrowColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_arrow_tint, textColor);
    hideArrow = typedArray.getBoolean(R.styleable.MaterialSpinner_ms_hide_arrow, false);
    typedArray.recycle();/*  w  ww . java 2  s  .  c o m*/

    setGravity(Gravity.CENTER_VERTICAL | Gravity.START);

    boolean rtl = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Configuration config = getResources().getConfiguration();
        rtl = config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
        if (rtl) {
            setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
            setTextDirection(View.TEXT_DIRECTION_RTL);
        }
    }

    Resources resources = getResources();
    int left, right, bottom, top;
    left = right = bottom = top = resources.getDimensionPixelSize(R.dimen.ms__padding_top);
    if (rtl) {
        right = resources.getDimensionPixelSize(R.dimen.ms__padding_left);
    } else {
        left = resources.getDimensionPixelSize(R.dimen.ms__padding_left);
    }

    setClickable(true);
    setPadding(left, top, right, bottom);
    setBackgroundResource(R.drawable.ms__selector);

    if (!hideArrow) {
        arrowDrawable = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ms__arrow));
        DrawableCompat.setTint(arrowDrawable, arrowColor);
        if (rtl) {
            setCompoundDrawablesWithIntrinsicBounds(arrowDrawable, null, null, null);
        } else {
            setCompoundDrawablesWithIntrinsicBounds(null, null, arrowDrawable, null);
        }
    }

    listView = new ListView(context);
    listView.setId(getId());
    listView.setDivider(null);
    listView.setItemsCanFocus(true);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position >= selectedIndex && position < adapter.getCount()) {
                position++;
            }
            selectedIndex = position;
            nothingSelected = false;
            Object item = adapter.get(position);
            adapter.notifyItemSelected(position);
            setText(item.toString());
            collapse();
            if (onItemSelectedListener != null) {
                //noinspection unchecked
                onItemSelectedListener.onItemSelected(MaterialSpinner.this, position, id, item);
            }
        }
    });

    popupWindow = new PopupWindow(context);
    popupWindow.setContentView(listView);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setFocusable(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        popupWindow.setElevation(16);
        popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ms__drawable));
    } else {
        popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ms__drop_down_shadow));
    }

    if (backgroundColor != Color.WHITE) { // default color is white
        setBackgroundColor(backgroundColor);
    }
    if (textColor != defaultColor) {
        setTextColor(textColor);
    }

    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

        @Override
        public void onDismiss() {
            if (nothingSelected && onNothingSelectedListener != null) {
                onNothingSelectedListener.onNothingSelected(MaterialSpinner.this);
            }
            if (!hideArrow) {
                animateArrow(false);
            }
        }
    });
}

From source file:cn.hollo.www.custom_view.PagerSlidingTabStrip.java

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

    setFillViewport(true);//from w w w  . jav a2s  . com
    setWillNotDraw(false);

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

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    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);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // 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);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    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);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);
    tabTextColor = a.getColorStateList(R.styleable.PagerSlidingTabStrip_pstsTabTextColor);
    defaultTabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTabTextColor, defaultTabTextColor);
    tabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabTextSize, tabTextSize);
    tabTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextTypeStyle, tabTypefaceStyle);
    tabIconArrayResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabIconRight, 0);
    tabViewRes = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabView, tabViewRes);

    a.recycle();

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

    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.smart.library.widget.PagerSlidingTabStrip.java

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

    setFillViewport(true);/* w  ww. ja  v  a2s.  c  o  m*/
    setWillNotDraw(false);

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

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    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);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

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

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(1, tabTextColor);

    a.recycle();

    // get custom attrs

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    selectedTabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsSelectedTabTextColor,
            selectedTabTextColor);
    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);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);
    pstsMatrix = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsMatrix, pstsMatrix);

    a.recycle();

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

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

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

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

From source file:piuk.blockchain.android.util.ActionBarFragment.java

public void addView(final View viewToAdd) {
    final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            getResources().getDimensionPixelSize(R.dimen.action_bar_button_width),
            android.view.ViewGroup.LayoutParams.FILL_PARENT, 0f);

    params.gravity = Gravity.CENTER_VERTICAL;

    view.addView(viewToAdd, 2, params);//from w  w  w .  ja  va  2s  . c o m

    final ImageView separator1 = new ImageView(getActivity());
    separator1.setImageDrawable(new ColorDrawable(Color.parseColor("#44ffffff")));
    view.addView(separator1, 2, separatorParams);

    final ImageView separator2 = new ImageView(getActivity());
    separator2.setImageDrawable(new ColorDrawable(Color.parseColor("#44000000")));
    view.addView(separator2, 2, separatorParams);
}