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:es.curso.android.streamingVLC.VideoActivity.java

/*************
 * Player//from  w w w  . jav  a 2 s . c o m
 *************/

private void createPlayer(String media) {
    releasePlayer();

    if (media.length() > 0) {
        Toast toast = Toast.makeText(this, media, Toast.LENGTH_LONG);
        toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        toast.show();
    }

    // Create a new media player
    try {
        libvlc = LibVLC.getInstance();
    } catch (LibVlcException e) {
        Toast.makeText(this, "Can't create player", Toast.LENGTH_LONG).show();
        return;
    }
    libvlc.setIomx(false);
    libvlc.setSubtitlesEncoding("");
    libvlc.setAout(LibVLC.AOUT_OPENSLES);
    libvlc.setTimeStretching(true);
    libvlc.setChroma("RV32");
    libvlc.setVerboseMode(true);
    LibVLC.restart(this);
    EventHandler.getInstance().addHandler(mHandler);
    if (holder == null)
        Log.d(TAG, "holder==null");
    holder.setFormat(PixelFormat.RGBX_8888);
    holder.setKeepScreenOn(true);
    MediaList list = libvlc.getMediaList();
    list.clear();
    list.add(new Media(libvlc, LibVLC.PathToURI(media)), false);
    libvlc.playIndex(0);

}

From source file:com.research.widget.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    LinearLayout item = new LinearLayout(getContext());
    item.setOrientation(LinearLayout.HORIZONTAL);
    item.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

    TextView tab = new TextView(getContext());
    tab.setText(title);/*from w ww . j a v a 2 s .com*/
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    TextView msgTipText = new TextView(getContext());
    msgTipText.setGravity(Gravity.CENTER);
    msgTipText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
    msgTipText.setSingleLine();
    msgTipText.setTextColor(Color.parseColor("#ffffff"));
    if (position != 0) {
        msgTipText.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.main_find_icon));
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                FeatureFunction.dip2px(BMapApiApp.getInstance(), 10),
                FeatureFunction.dip2px(BMapApiApp.getInstance(), 10));
        msgTipText.setLayoutParams(params);
    } else {
        msgTipText.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.message_count_bg));
    }

    msgTipText.setVisibility(View.GONE);

    item.addView(tab);
    item.addView(msgTipText);

    addTab(position, item);
}

From source file:ua.com.spacetv.mycookbook.dialogs.FragDialog.java

private void initAllViewsInDialog() {
    adb = new AlertDialog.Builder(getActivity());
    input = new EditText(getActivity());
    listView = new ListView(getActivity());
    textView = new TextView(getActivity());

    int paddingH = (int) getResources().getDimension(R.dimen.dialog_padding_left_right);
    int paddingV = (int) getResources().getDimension(R.dimen.dialog_padding_up_down);

    int textColor;
    if (Build.VERSION.SDK_INT >= 21) {
        //Getting color from current theme
        TypedValue typedValue = new TypedValue();
        mContext.getTheme().resolveAttribute(android.R.attr.colorPrimary, typedValue, true);
        int barColor = typedValue.data;
        textView.setBackgroundColor(barColor);
        textColor = ContextCompat.getColor(mContext, R.color.colorWhite);
    } else {/*from w w w .  jav  a  2 s.  c  o  m*/
        textColor = ContextCompat.getColor(mContext, R.color.colorBlack);
    }

    if (Build.VERSION.SDK_INT < 23) {
        textView.setTextAppearance(mContext, android.R.style.TextAppearance_Large);
    } else {
        textView.setTextAppearance(android.R.style.TextAppearance_Large);
    }

    textView.setTextColor(textColor);
    textView.setGravity(Gravity.CENTER_HORIZONTAL);

    textView.setPadding(paddingH, paddingV, paddingH, paddingV);
    input.setPadding(paddingH, paddingV, paddingH, paddingV);

    listView.setSelected(true);
    listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    listView.setSelector(R.drawable.list_color_selector);
    listView.setOnItemClickListener(this);
    listView.requestFocus();
}

From source file:app.learning.fantaster.nhatkyhoctiengnhat.util.slidingtab.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;//from w w w.  ja  va  2 s .c  o  m
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        CharSequence title = adapter.getPageTitle(i);
        tabTitleView.setText(title);
        tabTitleView.setGravity(Gravity.CENTER_HORIZONTAL);
        tabTitleView.setTextColor(Color.WHITE);
        tabView.setOnClickListener(tabClickListener);

        if (mDistributeEvenly) {
            tabView.setLayoutParams(layoutParams);
        }

        mTabStrip.addView(tabView);
    }
}

From source file:com.tmall.ultraviewpager.sample.PagerActivity.java

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    if (ultraViewPager.getIndicator() == null) {
        ultraViewPager.initIndicator();/*from   w  ww  .j a va  2  s.  c om*/
        ultraViewPager.getIndicator().setOrientation(gravity_indicator);
    }
    if (parent == indicatorStyle) {
        switch (position) {
        case 0:
            ultraViewPager.disableIndicator();
            break;
        case 1:
            ultraViewPager.getIndicator().setFocusResId(0).setNormalResId(0);
            ultraViewPager.getIndicator().setFocusColor(Color.GREEN).setNormalColor(Color.WHITE)
                    .setRadius((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5,
                            getResources().getDisplayMetrics()));
            break;
        case 2:
            ultraViewPager.getIndicator().setFocusResId(R.mipmap.tm_biz_lifemaster_indicator_selected)
                    .setNormalResId(R.mipmap.tm_biz_lifemaster_indicator_normal);
            break;
        case 3:
            break;
        }
    }
    if (parent == indicatorGravityHor) {
        switch (position) {
        case 0:
            gravity_hor = Gravity.LEFT;
            break;
        case 1:
            gravity_hor = Gravity.RIGHT;
            break;
        case 2:
            gravity_hor = Gravity.CENTER_HORIZONTAL;
            break;
        }
        if (ultraViewPager.getIndicator() != null) {
            if (gravity_ver != 0) {
                ultraViewPager.getIndicator().setGravity(gravity_hor | gravity_ver);
            } else {
                ultraViewPager.getIndicator().setGravity(gravity_hor);
            }
        }
    }
    if (parent == indicatorGravityVer) {
        switch (position) {
        case 0:
            gravity_ver = Gravity.TOP;
            break;
        case 1:
            gravity_ver = Gravity.BOTTOM;
            break;
        case 2:
            gravity_ver = Gravity.CENTER_VERTICAL;
            break;
        }
        if (ultraViewPager.getIndicator() != null) {
            if (gravity_hor != 0) {
                ultraViewPager.getIndicator().setGravity(gravity_hor | gravity_ver);
            } else {
                ultraViewPager.getIndicator().setGravity(gravity_ver);
            }
        }
    }
}

From source file:com.yunluo.android.arcadehub.GameListActivity.java

private void initSliding() {

    slidingDisable();//from w  ww.j  av  a  2  s  .c  o  m

    initLeftView();

    mMainLayout = new RelativeLayout(this);
    mMainLayout.setGravity(Gravity.CENTER_HORIZONTAL);

    mFrameLayout = new FrameLayout(this);

    setContentView(mFrameLayout);

    initRightView();

    mListShowView = mRightView.getListShowView();

    getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

    if (null != mListShowView) {
        mListShowView.firstRefresh();
    }

}

From source file:com.tiancaicc.springfloatingactionmenu.SpringFloatingActionMenu.java

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);

    Resources resources = getResources();
    Activity context = (Activity) mContext;

    // layout FAB and follow circles
    int fabWidth = mFAB.getMeasuredWidth();
    int fabHeight = mFAB.getMeasuredHeight();
    int bottomInsets = Utils.getInsetsBottom(context, this);

    int fabX = 0;
    int fabY = 0;
    if (mGravity == (Gravity.BOTTOM | Gravity.RIGHT)) {
        int marginX = Utils.dpToPx(mMarginSize, resources);
        int marginY = Utils.dpToPx(mMarginSize, resources) + bottomInsets;
        fabX = right - fabWidth - marginX;
        fabY = bottom - fabHeight - marginY;
        mFAB.layout(fabX, fabY, fabX + fabWidth, fabY + fabHeight);
    } else if (mGravity == (Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM)) {
        int marginY = Utils.dpToPx(mMarginSize, resources) + bottomInsets;
        fabX = right / 2 - fabWidth / 2;
        fabY = bottom - fabHeight - marginY;
        mFAB.layout(fabX, fabY, fabX + fabWidth, fabY + fabHeight);
    } else {/*  w  w w .j a  va2  s. c om*/
        throw new IllegalStateException("gravity only support bottom center and bottom right");
    }

    int fabCenterX = fabX + fabWidth / 2;
    int fabCenterY = fabY + fabHeight / 2;

    for (ImageButton circle : mFollowCircles) {
        int x = fabCenterX - circle.getWidth() / 2;
        int y = fabCenterY - circle.getHeight() / 2;
        circle.layout(x, y, x + circle.getMeasuredWidth(), y + circle.getMeasuredHeight());
    }

    int x = fabCenterX - mRevealCircle.getWidth() / 2;
    int y = fabCenterY - mRevealCircle.getHeight() / 2;
    mRevealCircle.layout(x, y, x + mRevealCircle.getMeasuredWidth(), y + mRevealCircle.getMeasuredHeight());

    //layout menu items
    layoutMenuItems(left, top, right, bottom);
}

From source file:net.yanzm.mth.MaterialTabHost.java

public void setType(Type type) {
    this.type = type;

    switch (type) {
    case FullScreenWidth:
        tabWidget.setGravity(Gravity.LEFT);
        setPadding(0, 0, 0, 0);/*  w w  w  . jav a 2s  .  c  o  m*/
        break;
    case Centered:
        tabWidget.setGravity(Gravity.CENTER_HORIZONTAL);
        setPadding(0, 0, 0, 0);
        break;
    case LeftOffset:
        tabWidget.setGravity(Gravity.LEFT);
        setPadding(leftOffset, 0, 0, 0);
        break;
    default:
        tabWidget.setGravity(Gravity.LEFT);
        setPadding(0, 0, 0, 0);
    }
}

From source file:org.rm3l.ddwrt.tiles.DDWRTTile.java

@Override
public final void onClick(View view) {
    final OnClickIntent onClickIntentAndListener = getOnclickIntent();
    final Intent onClickIntent;
    if (onClickIntentAndListener != null && (onClickIntent = onClickIntentAndListener.getIntent()) != null) {
        final String dialogMsg = onClickIntentAndListener.getDialogMessage();
        //noinspection ConstantConditions
        final AlertDialog alertDialog = Utils.buildAlertDialog(mParentFragmentActivity, null,
                Strings.isNullOrEmpty(dialogMsg) ? "Loading detailed view..." : dialogMsg, false, false);
        alertDialog.show();/*from  w  w  w  .ja v a 2s .  c  o  m*/
        ((TextView) alertDialog.findViewById(android.R.id.message)).setGravity(Gravity.CENTER_HORIZONTAL);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                ((DDWRTBaseFragment) mParentFragment).startActivityForResult(onClickIntent,
                        onClickIntentAndListener.getListener());
                alertDialog.cancel();
            }
        }, 2500);
    }
}

From source file:com.hcpt.fastfood.widget.PagerSlidingTabStrip.java

private void addTextTab(final int position) {

    TextView tab = new TextView(getContext());
    if (!arrTabs.isEmpty()) {
        // Set text
        tab.setText(arrTabs.get(position).getTitle());
        tab.setTypeface(null, Typeface.BOLD);
        tab.setGravity(Gravity.CENTER_HORIZONTAL);
        tab.setSingleLine();/*from  w w  w.  j a v a 2s . c  om*/

        // Set icon

        Drawable iconDrawable = getResources().getDrawable(arrTabs.get(position).getIcon());
        tab.setCompoundDrawablesWithIntrinsicBounds(null, iconDrawable, null, null);
    }

    addTab(position, tab);
}