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.bt.download.android.gui.util.UIUtils.java

public static void showToastMessage(Context context, String message, int duration) {
    showToastMessage(context, message, duration, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 0);
}

From source file:autobahn.demo.com.autobahndemo.EchoClientActivity.java

private void alert(String message) {
    Toast toast = Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
    toast.show();//from   w w  w. j a v a  2  s .co  m
}

From source file:freed.cam.ui.themesample.cameraui.HorizontalValuesFragment.java

private LinearLayout getNewLayout() {
    LinearLayout linearLayout = new LinearLayout(getContext());
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    linearLayout.setLayoutParams(params);
    linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);
    valuesHolder.addView(linearLayout);/*from   ww w.  jav a  2 s.  co  m*/
    return linearLayout;
}

From source file:com.pseudosudostudios.jdd.fragments.ScoreFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    View view = inflater.inflate(R.layout.score_display, container, false);
    // Find the user's profile picture custom view
    // Find the user's name view
    userNameView = (TextView) view.findViewById(R.id.selection_user_name);
    scoreDisplay = (TextView) view.findViewById(R.id.scoreDisplay);
    movesDisplay = (TextView) view.findViewById(R.id.movesDisplay);
    timeDisplay = (TextView) view.findViewById(R.id.timeDisplay);
    playAgain = (Button) view.findViewById(R.id.playAgainButton);
    highScores = (ListView) view.findViewById(R.id.high_score_list_view);

    signIn = view.findViewById(R.id.sign_in_button_google_play_services);
    signOut = view.findViewById(R.id.sign_out_button);

    TextView tv = new TextView(getActivity());
    tv.setText(getActivity().getString(R.string.high_scores));
    tv.setTextSize(20);/*from  w ww. j  ava  2  s . co  m*/
    tv.setGravity(Gravity.CENTER_HORIZONTAL);
    tv.setPadding(0, 6, 0, 6);
    highScores.addHeaderView(tv);

    shareSocial = (Button) view.findViewById(R.id.social_share);
    shareSocial.setVisibility(View.INVISIBLE);

    // onClickListeners
    shareSocial.setOnClickListener(this);

    signIn.setOnClickListener(this);
    signOut.setOnClickListener(this);

    return view;
}

From source file:com.vivavu.dream.view.PagerContainer.java

@Override
protected void onFinishInflate() {
    try {//  w  w w .ja  va2 s  .  c o  m

        mPager = new ViewPager(mContext);
        int width = (int) getResources().getDimension(R.dimen.book_width_dp);
        int height = (int) getResources().getDimension(R.dimen.book_height_dp);
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(width, height,
                Gravity.CENTER_HORIZONTAL);
        mPager.setLayoutParams(layoutParams);
        mPager.setId(AndroidUtils.generateViewId());
        //mPager.setId(R.id.shelf_pager);
        this.addView(mPager, 0);
        /*mPager = (ViewPager) getChildAt(0);
        mPager.setOnPageChangeListener(this);*/
    } catch (Exception e) {
        throw new IllegalStateException("The root child of PagerContainer must be a ViewPager");
    }
}

From source file:com.ez.gallery.ucrop.view.widget.AspectRatioTextView.java

@SuppressWarnings("deprecation")
private void init(@NonNull TypedArray a) {
    setGravity(Gravity.CENTER_HORIZONTAL);

    mAspectRatioTitle = a.getString(R.styleable.ucrop_AspectRatioTextView_ucrop_artv_ratio_title);
    mAspectRatioX = a.getFloat(R.styleable.ucrop_AspectRatioTextView_ucrop_artv_ratio_x,
            CropImageView.SOURCE_IMAGE_ASPECT_RATIO);
    mAspectRatioY = a.getFloat(R.styleable.ucrop_AspectRatioTextView_ucrop_artv_ratio_y,
            CropImageView.SOURCE_IMAGE_ASPECT_RATIO);

    if (mAspectRatioX == CropImageView.SOURCE_IMAGE_ASPECT_RATIO
            || mAspectRatioY == CropImageView.SOURCE_IMAGE_ASPECT_RATIO) {
        mAspectRatio = CropImageView.SOURCE_IMAGE_ASPECT_RATIO;
    } else {/*from   www.j  a  va2s . c  o  m*/
        mAspectRatio = mAspectRatioX / mAspectRatioY;
    }

    mDotSize = getContext().getResources().getDimensionPixelSize(R.dimen.ucrop_size_dot_scale_text_view);
    mDotPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDotPaint.setStyle(Paint.Style.FILL);

    setTitle();

    int activeColor = getResources().getColor(R.color.ucrop_color_widget_active);
    applyActiveColor(activeColor);
}

From source file:com.example.android.MainActivity.java

/**Display JSON data in table format on the user interface of android app
 * by clicking on the button 'Start'*/
@Override//from  w  w w.j a  v a2s. co  m
protected void onCreate(Bundle savedInstanceState) {
    /**
     * Declares TextView, Button and Tablelayout to retrieve the widgets 
     * from User Interface. Insert the TableRow into Table and set the 
     * gravity, font size  and id of table rows and columns.
     * 
     * Due to great amount of JSON data, 'for' loop method is used to insert 
     * the new rows and columns in the table. In each loop, each of rows and 
     * columns are set to has its own unique id. This purpose of doing this 
     * is to allows the user to read and write the text of specific rows and 
     * columns easily.
     */
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    progress = new ProgressDialog(this);
    StartDisplay = (Button) findViewById(R.id.btnDisplay);
    profile = (TableLayout) findViewById(R.id.tableLayout1);
    profile.setStretchAllColumns(true);
    profile.bringToFront();

    for (int i = 1; i < 11; i++) {
        TableRow tr = new TableRow(this);
        TextView c1 = new TextView(this);
        TextView c2 = new TextView(this);
        c1.setId(i * 10 + 1);
        c1.setTextSize(12);
        c1.setGravity(Gravity.CENTER);
        c2.setId(i * 10 + 2);
        c2.setTextSize(12);
        c2.setGravity(Gravity.CENTER);
        tr.addView(c1);
        tr.addView(c2);
        tr.setGravity(Gravity.CENTER_HORIZONTAL);
        profile.addView(tr);
    }

    /**
    * onClick: Executes the DownloadWebPageTask once OnClick event occurs. 
    * When user click on the "Start" button, 
    * 1)the JSON data will be read from URL 
    * 2)Progress bar will be shown till all data is read and displayed in
    * table form. Once it reaches 100%, it will be dismissed. 
    * 
    * Progress Bar: The message of the progress bar is obtained from strings.xml.
    * New thread is created to handle the action of the progress bar. 
    */
    StartDisplay.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            final String TAG = "MyActivity";
            progress.setMessage(getResources().getString(R.string.ProgressBar_message));
            progress.setCancelable(true);
            progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progress.setProgress(0);
            progress.setMax(100);
            progress.show();
            new Thread(new Runnable() {

                public void run() {
                    while (ProgressBarStatus < 100) {

                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                            Log.e(TAG, Log.getStackTraceString(e));
                        }
                        progressBarbHandler.post(new Runnable() {
                            public void run() {
                                progress.setProgress(ProgressBarStatus);
                            }
                        });
                    }

                    if (ProgressBarStatus >= 100) {

                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            Log.e(TAG, Log.getStackTraceString(e));
                        }

                        progress.dismiss();
                    }
                }
            }).start();
            DownloadWebPageTask task = new DownloadWebPageTask();
            task.execute("http://private-ae335-pgserverapi.apiary.io/user/profile/234");
            StartDisplay.setClickable(false);
        }
    });

}

From source file:com.lokiy.widget.BannerView.java

public BannerView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.BannerView);
    isShowIndicator = a.getBoolean(R.styleable.BannerView_showIndicator, true);
    mIndicatorId = a.getResourceId(R.styleable.BannerView_indicator, 0);
    isCorner = a.getBoolean(R.styleable.BannerView_corner, false);
    mRectRoundRadius = a.getDimensionPixelOffset(R.styleable.BannerView_cornerRadii, 0);
    mPageMargin = a.getDimensionPixelSize(R.styleable.BannerView_pageMargin, 0);
    int mIndicatorGravity = a.getInt(R.styleable.BannerView_indicator_gravity,
            Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
    a.recycle();/* ww  w .j  av  a2 s  .  c  om*/
    mViewPager = new XViewPager(getContext(), null);
    mViewPager.setPageMargin(mPageMargin);
    setClipChildren(false);
    mAdapter = new BannerAdapter();
    //noinspection deprecation
    mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageSelected(int position) {
            position = position % mAdapter.getRealCount();
            if (isShowIndicator) {
                vRadioGroup.check(position);
            }
            if (onPageSelectedListener != null) {
                onPageSelectedListener.onPageSelected(position, mAdapter.mBannerList.get(position));
            }
        }

        @Override
        public void onPageScrollStateChanged(int position) {
        }
    });
    mViewPager.setAdapter(mAdapter);
    addView(mViewPager, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    if (isShowIndicator) {
        vRadioGroup = new RadioGroup(getContext());
        LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.gravity = mIndicatorGravity;
        vRadioGroup.setGravity(Gravity.CENTER);
        vRadioGroup.setOrientation(LinearLayout.HORIZONTAL);
        addView(vRadioGroup, params);
    }
}

From source file:cm.aptoide.pt.webservices.login.CreateUser.java

public void signUp(View v) {
    username = username_box.getText().toString();
    password = password_box.getText().toString();
    if (username.trim().length() > 0 && password.trim().length() > 0) {
        new CreateUserTask().execute(username.trim(), password.trim());
    } else {//from  w w  w  . ja  v  a  2s .  c om
        Toast toast = Toast.makeText(context, context.getString(R.string.check_your_credentials),
                Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 30);
        toast.show();
    }

}

From source file:com.frostwire.android.gui.util.UIUtils.java

private static void showToastMessage(Context context, String message, int duration, int gravity, int xOffset,
        int yOffset) {
    if (context != null && message != null) {
        Toast toast = Toast.makeText(context, message, duration);
        if (gravity != (Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM)) {
            toast.setGravity(gravity, xOffset, yOffset);
        }//from  www  .  ja  va 2 s  . co m
        toast.show();
    }
}