Example usage for android.view Gravity CENTER

List of usage examples for android.view Gravity CENTER

Introduction

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

Prototype

int CENTER

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

Click Source Link

Document

Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.

Usage

From source file:com.bangqu.eshow.view.sliding.ESSlidingPlayView.java

/**
 * .//ww w .jav  a2s .c  o m
 */
public void creatIndex() {
    //?
    navLinearLayout.removeAllViews();
    mNavLayoutParent.setHorizontalGravity(navHorizontalGravity);
    navLinearLayout.setGravity(Gravity.CENTER);
    navLinearLayout.setVisibility(View.VISIBLE);
    count = mListViews.size();
    navLayoutParams.setMargins(5, 5, 5, 5);
    navLayoutParams.width = 15;
    navLayoutParams.height = 15;
    for (int j = 0; j < count; j++) {
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(navLayoutParams);
        if (j == 0) {
            imageView.setImageDrawable(displayDrawable);
        } else {
            imageView.setImageDrawable(hideDrawable);
        }
        ESViewUtil.scaleView(imageView);
        navLinearLayout.addView(imageView, j);
    }

}

From source file:br.com.cast.treinamento.tabs.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)}.
 *///w  ww  . j  av  a  2s  . com
@SuppressLint("NewApi")
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    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);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        textView.setAllCaps(true);
    }
    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:cn.org.eshow.framwork.view.sliding.AbSlidingPlayView.java

/**
 * .//from   w  w  w  .j av a  2s.co  m
 */
public void creatIndex() {
    //?
    navLinearLayout.removeAllViews();
    mNavLayoutParent.setHorizontalGravity(navHorizontalGravity);
    navLinearLayout.setGravity(Gravity.CENTER);
    navLinearLayout.setVisibility(View.VISIBLE);
    count = mListViews.size();
    navLayoutParams.setMargins(5, 5, 5, 5);
    navLayoutParams.width = 15;
    navLayoutParams.height = 15;
    for (int j = 0; j < count; j++) {
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(navLayoutParams);
        if (j == 0) {
            imageView.setImageDrawable(displayDrawable);
        } else {
            imageView.setImageDrawable(hideDrawable);
        }
        AbViewUtil.scaleView(imageView);
        navLinearLayout.addView(imageView, j);
    }

}

From source file:fm.smart.r1.activity.CreateExampleActivity.java

public void onClick(View v) {
    EditText exampleInput = (EditText) findViewById(R.id.create_example_sentence);
    EditText translationInput = (EditText) findViewById(R.id.create_example_translation);
    EditText exampleTransliterationInput = (EditText) findViewById(R.id.sentence_transliteration);
    EditText translationTransliterationInput = (EditText) findViewById(R.id.translation_transliteration);
    final String example = exampleInput.getText().toString();
    final String translation = translationInput.getText().toString();
    if (TextUtils.isEmpty(example) || TextUtils.isEmpty(translation)) {
        Toast t = Toast.makeText(this, "Example and translation are required fields", 150);
        t.setGravity(Gravity.CENTER, 0, 0);
        t.show();//from ww  w  .  ja  v  a  2 s  . c  o m
    } else {
        final String example_language_code = Utils.LANGUAGE_MAP.get(example_language);
        final String translation_language_code = Utils.LANGUAGE_MAP.get(translation_language);
        final String example_transliteration = exampleTransliterationInput.getText().toString();
        final String translation_transliteration = translationTransliterationInput.getText().toString();

        if (Main.isNotLoggedIn(this)) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(this, LoginActivity.class.getName());
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); // avoid
            // navigation
            // back to this?
            LoginActivity.return_to = CreateExampleActivity.class.getName();
            LoginActivity.params = new HashMap<String, String>();
            LoginActivity.params.put("list_id", list_id);
            LoginActivity.params.put("item_id", item_id);
            LoginActivity.params.put("example", example);
            LoginActivity.params.put("translation", translation);
            LoginActivity.params.put("example_language", example_language);
            LoginActivity.params.put("translation_language", translation_language);
            LoginActivity.params.put("example_transliteration", example_transliteration);
            LoginActivity.params.put("translation_transliteration", translation_transliteration);
            startActivity(intent);
        } else {

            final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
            myOtherProgressDialog.setTitle("Please Wait ...");
            myOtherProgressDialog.setMessage("Creating Example ...");
            myOtherProgressDialog.setIndeterminate(true);
            myOtherProgressDialog.setCancelable(true);

            final Thread create_example = new Thread() {
                public void run() {
                    // TODO make this interruptable .../*if
                    // (!this.isInterrupted())*/
                    try {
                        // TODO failures here could derail all ...
                        CreateExampleActivity.add_item_list_result = ItemActivity.addItemToList(list_id,
                                item_id, CreateExampleActivity.this);
                        CreateExampleActivity.create_example_result = createExample(example,
                                example_language_code, example_transliteration, translation,
                                translation_language_code, translation_transliteration, item_id, list_id);
                        CreateExampleActivity.add_sentence_list_result = ItemActivity.addSentenceToList(
                                CreateExampleActivity.create_example_result.http_response, item_id, list_id,
                                CreateExampleActivity.this);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    myOtherProgressDialog.dismiss();

                }
            };
            myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    create_example.interrupt();
                }
            });
            OnCancelListener ocl = new OnCancelListener() {
                public void onCancel(DialogInterface arg0) {
                    create_example.interrupt();
                }
            };
            myOtherProgressDialog.setOnCancelListener(ocl);
            myOtherProgressDialog.show();
            create_example.start();
        }
    }
}

From source file:android.support.common.view.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  w  w w  .  j ava  2 s  . c  o m*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    int color = getResources().getColor(R.color.color_clickable_gray_white);
    textView.setTextColor(color);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        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.ashoksm.pinfinder.common.view.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   w w  w . j  a  v  a2 s.co m*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextColor(Color.parseColor("#99ffffff"));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        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.ab.view.sliding.AbSlidingTabView_fix.java

/**
 * Inits the view./*from w ww  .  j  a v  a  2  s. c  o  m*/
 */
public void initView() {
    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    mTabScrollView = new HorizontalScrollView(context);
    mTabScrollView.setHorizontalScrollBarEnabled(false);
    mTabScrollView.setSmoothScrollingEnabled(true);

    mTabLayout = new LinearLayout(context);
    mTabLayout.setOrientation(LinearLayout.HORIZONTAL);
    mTabLayout.setGravity(Gravity.CENTER);

    // mTabLayout
    mTabScrollView.addView(mTabLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    this.addView(mTabScrollView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    // View?
    mViewPager = new AbViewPager(context);
    // ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();
    // Tab?
    tabItemList = new ArrayList<TextView>();
    tabItemTextList = new ArrayList<String>();
    tabItemDrawableList = new ArrayList<Drawable>();

    // ?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        AbLogUtil.e(AbSlidingTabView_fix.class,
                "AbSlidingTabView?context,FragmentActivity");
    }
}

From source file:br.liveo.sliding.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)}.// w  w  w  . j a  v  a  2 s  . c o  m
 */
@SuppressLint("NewApi")
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        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.starwood.anglerslong.LicenseActivity.java

private void createTextView() {

    if (isCreateTextViewSet)
        return;/*from w w  w  .  j a  v a  2  s  .c  om*/

    // Get the linear layout and set the parameters
    LinearLayout ll = (LinearLayout) findViewById(R.id.profile_ll);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.CENTER;

    TextView createLicense = new TextView(this);
    createLicense.setId(0);
    createLicense.setText(Html.fromHtml(getResources().getString(R.string.create_license_string)));
    createLicense.setPadding(70, 100, 70, 100);
    createLicense.setTextSize(18);
    ll.addView(createLicense, params);
    isCreateTextViewSet = true;
}

From source file:com.firesoft.member.Activity.F9_SettingActivity.java

@Override
public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status) throws JSONException {
    if (url.endsWith(ApiInterface.USER_CHANGE_AVATAR)) {
        ToastView toast = new ToastView(this, getString(R.string.change_avatar_success));
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();/*from w w w  .  j  a  v  a2 s.c o  m*/
    } else if (url.endsWith(ApiInterface.PUSH_SWITCH)) {
        //Todo
    } else if (url.endsWith(ApiInterface.USER_SIGNOUT)) {
        mEditor.putBoolean("isLogin", false);
        mEditor.putString("user", "");
        mEditor.putInt("uid", 0);
        mEditor.putString("sid", "");
        mEditor.commit();
        SESSION.getInstance().uid = mShared.getInt("uid", 0);
        SESSION.getInstance().sid = mShared.getString("sid", "");
        ToastView toast = new ToastView(F9_SettingActivity.this, getString(R.string.logout_success));
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
        Message msg = new Message();
        msg.what = MessageConstant.LOGINOUT;
        EventBus.getDefault().post(msg);
        Intent intent = new Intent(F9_SettingActivity.this, B0_SigninActivity.class);
        startActivity(intent);
        finish();
    }
}