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.knurld.dropboxdemo.KnurldActivity.java

public void showMessage(View view, String message) {
    Activity parent = (Activity) context;
    View spinnerView = LayoutInflater.from(parent).inflate(R.layout.instructions_popup, null);

    TextView textView = (TextView) spinnerView.findViewById(R.id.phraseText);
    textView.setText(message);/*from   ww w  .j a v  a 2  s.  co  m*/

    PopupWindow popupWindow = new PopupWindow(spinnerView, 500, 500);
    popupWindow.setFocusable(true);
    popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);

    final PopupWindow finalPopupWindow = popupWindow;
    new android.os.Handler().postDelayed(new Runnable() {
        public void run() {
            finalPopupWindow.dismiss();
        }
    }, 3000);

}

From source file:com.baoyz.bigbang.BigBangLayout.java

public void addTextItem(String text) {
    TextView view = new TextView(getContext());
    view.setText(text);/*from   w w  w. j  a  va 2 s  . c  o m*/
    view.setBackgroundResource(R.drawable.item_background);
    view.setTextColor(ContextCompat.getColorStateList(getContext(), R.color.bigbang_item_text));
    view.setGravity(Gravity.CENTER);
    addView(view);
}

From source file:by.istin.android.xcore.inherited.fragment.AdapterViewFragment.java

/**
 * Provide default implementation to return a simple list view.  Subclasses
 * can override to replace with their own layout.  If doing so, the
 * returned view hierarchy <em>must</em> have a ListView whose id
 * is {@link android.R.id#list android.R.id.list} and can optionally
 * have a sibling view id {@link android.R.id#empty android.R.id.empty}
 * that is to be shown when the list is empty.
 * //from   ww  w  . j  a  v a 2  s .  c om
 * <p>If you are overriding this method with your own custom content,
 * consider including the standard layout {@link android.R.layout#list_content}
 * in your layout file, so that you continue to retain all of the standard
 * behavior of ListFragment.  In particular, this is currently the only
 * way to have the built-in indeterminant progress state be shown.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);

    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    AdapterView<?> adapterView = createDefaultAbstractView();

    adapterView.setId(android.R.id.list);
    if (adapterView instanceof ListView) {
        ((ListView) adapterView).setDrawSelectorOnTop(false);
    }
    lframe.addView(adapterView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return root;
}

From source file:ch.arnab.simplelauncher.GridFragment.java

/**
 * Provide default implementation to return a simple grid view.  Subclasses
 * can override to replace with their own layout.  If doing so, the
 * returned view hierarchy <em>must</em> have a GridView whose id
 * is {@link android.R.id#list android.R.id.list} and can optionally
 * have a sibling view id {@link android.R.id#empty android.R.id.empty}
 * that is to be shown when the grid is empty.
 *
 * <p>If you are overriding this method with your own custom content,
 * consider including the standard layout {@link android.R.layout#list_content}
 * in your layout file, so that you continue to retain all of the standard
 * behavior of ListFragment.  In particular, this is currently the only
 * way to have the built-in indeterminant progress state be shown.
 *///from  ww  w. j  a v  a  2 s  .  c  om
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);

    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    GridView lv = new GridView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lv.setColumnWidth(convertDpToPixels(60, getActivity()));
    lv.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    lv.setNumColumns(GridView.AUTO_FIT);
    lv.setHorizontalSpacing(convertDpToPixels(20, getActivity()));
    lv.setVerticalSpacing(convertDpToPixels(20, getActivity()));
    lv.setSmoothScrollbarEnabled(true);

    // disable overscroll
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        lv.setOverScrollMode(ListView.OVER_SCROLL_NEVER);
    }

    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return root;
}

From source file:com.insthub.O2OMobile.Activity.G0_ReportActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.g0_report);/* ww w .java  2s  . c  o  m*/
    mBack = (ImageView) findViewById(R.id.top_view_back);
    mTitle = (TextView) findViewById(R.id.top_view_title);
    mComplainEdittext = (EditText) findViewById(R.id.d13_complain_edittext);
    mComplainButton = (Button) findViewById(R.id.d13_complain_button);

    Intent intent = getIntent();
    mOrderId = intent.getIntExtra("orderId", 0);
    mUserId = intent.getIntExtra("userId", 0);

    mBack.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            finish();
        }
    });
    mTitle.setText(getString(R.string.complain));

    mReportModel = new ReportModel(this);
    mReportModel.addResponseListener(this);

    mComplainButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            String str = mComplainEdittext.getText().toString();
            if (str.equals("")) {
                ToastView toast = new ToastView(G0_ReportActivity.this,
                        getString(R.string.input_complain_content));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else {
                mReportModel.report(mOrderId, mUserId, str);
            }
        }
    });

}

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

/**
 * Instantiates a new ab sliding smooth fix tab view.
 *
 * @param context the context/* w w  w.  jav  a2 s . c  o m*/
 * @param attrs the attrs
 */
public ESSlidingSmoothFixTabView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    layoutParamsFW = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    layoutParamsFF = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    layoutParamsWW = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    this.setOrientation(LinearLayout.VERTICAL);

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

    //Tab?
    tabItemList = new ArrayList<TextView>();
    tabItemTextList = new ArrayList<String>();

    this.addView(mTabLayout, layoutParamsFW);

    //?
    mTabImg = new ImageView(context);
    this.addView(mTabImg, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, tabSlidingHeight));

    //View?
    mViewPager = new ViewPager(context);
    //ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();

    this.addView(mViewPager, layoutParamsFF);

    //?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        ESLogUtil.e(ESSlidingSmoothFixTabView.class,
                "AbSlidingSmoothTabView?context,FragmentActivity");
    }

    DisplayMetrics mDisplayMetrics = ESAppUtil.getDisplayMetrics(context);
    mWidth = mDisplayMetrics.widthPixels;

    FragmentManager mFragmentManager = ((FragmentActivity) this.context).getFragmentManager();
    mFragmentPagerAdapter = new ESFragmentPagerAdapter(mFragmentManager, pagerItemList);
    mViewPager.setAdapter(mFragmentPagerAdapter);
    mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
    mViewPager.setOffscreenPageLimit(3);

}

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

/**
 * Instantiates a new ab sliding smooth fix tab view.
 *
 * @param context the context/*from  w w  w . ja v a 2s .c om*/
 * @param attrs the attrs
 */
public AbSlidingSmoothFixTabView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    layoutParamsFW = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    layoutParamsFF = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    layoutParamsWW = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    this.setOrientation(LinearLayout.VERTICAL);

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

    //Tab?
    tabItemList = new ArrayList<TextView>();
    tabItemTextList = new ArrayList<String>();

    this.addView(mTabLayout, layoutParamsFW);

    //?
    mTabImg = new ImageView(context);
    this.addView(mTabImg, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, tabSlidingHeight));

    //View?
    mViewPager = new ViewPager(context);
    //ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();

    this.addView(mViewPager, layoutParamsFF);

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

    DisplayMetrics mDisplayMetrics = AbAppUtil.getDisplayMetrics(context);
    mWidth = mDisplayMetrics.widthPixels;

    FragmentManager mFragmentManager = ((FragmentActivity) this.context).getFragmentManager();
    mFragmentPagerAdapter = new AbFragmentPagerAdapter(mFragmentManager, pagerItemList);
    mViewPager.setAdapter(mFragmentPagerAdapter);
    mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
    mViewPager.setOffscreenPageLimit(3);

}

From source file:hongik.android.project.best.HistoryActivity.java

public void drawHistory() {
    int rowCnt = historyTable.getChildCount();
    Log.i("ROWCOUNT", rowCnt + "");
    String query = "func=history&cid=" + cid;
    DBConnector conn = new DBConnector(query);
    conn.start();/*from   w w w.j av a 2  s .  com*/

    try {
        conn.join();
        JSONObject jsonResult = conn.getResult();
        boolean result = (boolean) jsonResult.get("result");

        if (!result)
            return;

        TableRow motive = (TableRow) historyTable.getChildAt(1);
        JSONArray jsonArray = jsonResult.getJSONArray("values");

        for (int i = 0; i < jsonArray.length(); i++) {
            TableRow tbRow = new TableRow(this);
            final TextViewPlus[] tbCols = new TextViewPlus[4];
            JSONObject json = jsonArray.getJSONObject(i);
            String[] elements = new String[4];

            elements[0] = json.getString("SNAME");
            elements[1] = Double.parseDouble(json.getString("GRADE")) + "";
            elements[2] = json.getString("NOTE");
            elements[3] = json.getString("DAY");
            final String license = json.getString("LICENSE#");

            if (elements[2].length() > 14)
                elements[2] = elements[2].substring(0, 14) + "...";

            for (int j = 0; j < 4; j++) {
                tbCols[j] = new TextViewPlus(this);
                tbCols[j].setText(elements[j]);
                tbCols[j].setLayoutParams(motive.getChildAt(j).getLayoutParams());
                tbCols[j].setGravity(Gravity.CENTER);
                tbCols[j].setTypeface(Typeface.createFromAsset(tbCols[j].getContext().getAssets(),
                        "InterparkGothicBold.ttf"));
                final HistoryActivity originActivity = this;
                tbCols[j].setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent reviewIntent = new Intent(originActivity, ReviewDetailActivity.class);
                        reviewIntent.putExtra("ACCESS", "HISTORY");
                        reviewIntent.putExtra("CID", cid);
                        reviewIntent.putExtra("LICENSE", license);
                        startActivity(reviewIntent);
                    }
                });

                Log.i("History", "COL" + j + ":" + elements[j]);

                tbRow.addView(tbCols[j]);
            }
            historyTable.addView(tbRow);
        }
        for (int i = 1; i < rowCnt; i++) {
            historyTable.removeViewAt(1);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:am.project.x.business.drawables.cornerdrawable.CornerDrawableActivity.java

@SuppressLint("RtlHardcoded")
@Override/*from  w  w  w  . j av  a2  s  . c o m*/
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    switch (parent.getId()) {
    case R.id.cnd_sp_direction:
        switch (position) {
        default:
        case 0:
            drawable.setDirection(Gravity.TOP);
            break;
        case 1:
            drawable.setDirection(Gravity.LEFT);
            break;
        case 2:
            drawable.setDirection(Gravity.RIGHT);
            break;
        case 3:
            drawable.setDirection(Gravity.BOTTOM);
            break;
        }
        break;
    case R.id.cnd_sp_location:
        switch (position) {
        default:
        case 0:
            drawable.setLocation(Gravity.CENTER);
            break;
        case 1:
            drawable.setLocation(Gravity.LEFT);
            break;
        case 2:
            drawable.setLocation(Gravity.RIGHT);
            break;
        }
        break;
    }
}

From source file:com.insthub.O2OMobile.Activity.C16_FeedbackActivity.java

@Override
public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status) throws JSONException {
    if (url.endsWith(ApiInterface.FEEDBACK)) {
        ToastView toast = new ToastView(this, getString(R.string.feedback_success));
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();//from   w  w w .j  a  v  a 2 s .  c  o m
        finish();
    }
}