Example usage for android.widget TextView setGravity

List of usage examples for android.widget TextView setGravity

Introduction

In this page you can find the example usage for android.widget TextView setGravity.

Prototype

public void setGravity(int gravity) 

Source Link

Document

Sets the horizontal alignment of the text and the vertical gravity that will be used when there is extra space in the TextView beyond what is required for the text itself.

Usage

From source file:com.aaagame.proframework.fragment.T_PaletteFragment.java

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

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    FrameLayout fl = new FrameLayout(getActivity());
    fl.setLayoutParams(params);/*from ww  w .j  a  v a2s .  c o  m*/
    fl.setBackgroundResource(drawables[position]);
    final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());

    TextView v = new TextView(getActivity());
    params.setMargins(margin, margin, margin, margin);
    v.setLayoutParams(params);
    v.setLayoutParams(params);
    v.setGravity(Gravity.BOTTOM);
    v.setText("CARD " + (position + 1));

    fl.addView(v);
    return fl;
}

From source file:com.commnsense.proximity.fragments.SuperAwesomeCardFragment.java

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

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    FrameLayout fl = new FrameLayout(getActivity());
    fl.setLayoutParams(params);/*  w  w w  .j  a v a  2 s. co m*/
    fl.setBackgroundColor(0xffa9a9a9);

    final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());

    TextView v = new TextView(getActivity());
    params.setMargins(margin, margin, margin, margin);
    v.setLayoutParams(params);
    v.setLayoutParams(params);
    v.setGravity(Gravity.CENTER);
    v.setBackgroundResource(R.drawable.background_card);
    v.setText("CARD " + (position + 1));

    fl.addView(v);
    return fl;
}

From source file:com.eric.quora.fragment.SuperAwesomeCardFragment.java

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

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    FrameLayout fl = new FrameLayout(getActivity());
    fl.setLayoutParams(params);/*from  www . j  a  v a  2  s. c  o  m*/
    fl.setBackgroundResource(mipmaps[position]);
    final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());

    TextView v = new TextView(getActivity());
    params.setMargins(margin, margin, margin, margin);
    v.setLayoutParams(params);
    v.setLayoutParams(params);
    v.setGravity(Gravity.BOTTOM);
    v.setText("CARD " + (position + 1));

    fl.addView(v);
    return fl;
}

From source file:com.karthikb351.vitinfo2.fragment.grades.GradesFragment.java

TextView createTextView(String text) {
    TextView tv = new TextView(getActivity());
    tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    tv.setGravity(Gravity.CENTER);
    tv.setTextSize(18);/*from w ww  . java2s  .co  m*/
    tv.setPadding(0, 5, 0, 5);
    tv.setText(text);
    return tv;
}

From source file:cc.metapro.openct.customviews.DuringDialog.java

private void setViews(GridLayout gridLayout) {
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 6; j++) {
            final int week = i * 6 + j + 1;
            final TextView textView = new TextView(getActivity());
            textView.setText(week + gridLayout.getContext().getString(R.string.week));
            textView.setGravity(Gravity.CENTER);
            if (DURING[week]) {
                textView.setBackground(//from   w  ww.ja va  2  s .  c  om
                        ContextCompat.getDrawable(getActivity(), R.drawable.text_view_card_style_blue));
                textView.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorAccent));
            } else {
                textView.setBackground(
                        ContextCompat.getDrawable(getActivity(), R.drawable.text_view_card_style_grey));
                textView.setTextColor(ContextCompat.getColor(getActivity(), R.color.material_grey));
            }

            textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    DURING[week] = !DURING[week];
                }
            });
            GridLayout.Spec row = GridLayout.spec(i, 1, 1);
            GridLayout.Spec col = GridLayout.spec(j, 1, 1);
            GridLayout.LayoutParams params = new GridLayout.LayoutParams(row, col);
            gridLayout.addView(textView, params);
            selections[i][j] = textView;
        }
    }
}

From source file:am.project.x.business.widgets.indicatortabstrip.IndicatorTabStripActivity.java

private ArrayList<View> getPagers() {
    ArrayList<View> views = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        TextView text = new TextView(this);
        text.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 180);
        text.setText(String.format(Locale.getDefault(), "%d", i + 1));
        text.setGravity(Gravity.CENTER);
        text.setTextColor(0xff000000);/*  w ww . j  av  a 2 s  .  co m*/
        views.add(text);
    }
    return views;
}

From source file:com.endiansoftware.echo.remotewatch.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    /*//from w  w  w  .j a v a2 s .  c om
       // Explicitly specify that GcmIntentService will handle the intent.
    ComponentName comp = new ComponentName(context.getPackageName(),
        GcmIntentService.class.getName());
    // Start the service, keeping the device awake while it is launching.
    startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);
    */

    /*
    // ?    ?? .
    Intent popupIntent = new Intent(context, Popup.class)
        .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    //  .
    context.startActivity(popupIntent);
            
    */

    LinearLayout layout = new LinearLayout(context);
    //layout.setBackgroundResource(R.color.LightOrange);

    TextView tv = new TextView(context);
    // set the TextView properties like color, size etc
    tv.setTextColor(Color.RED);
    tv.setTextSize(15);

    tv.setGravity(Gravity.CENTER_VERTICAL);

    // set the text you want to show in  Toast
    tv.setText("My Custom Toast at Bottom of Screen");

    layout.addView(tv);

    Toast toast = new Toast(context); //context is object of Context write "this" if you are an Activity
    // Set The layout as Toast View
    toast.setView(layout);

    // Position you toast here toast position is 50 dp from bottom you can give any integral value
    toast.setGravity(Gravity.BOTTOM, 0, 50);
    toast.show();
}

From source file:com.photocitygame.android.ImageActivity.java

private void addScoreRow(TableLayout scoreTable, String team, int score) {
    TableRow row = new TableRow(this);
    TextView tv = new TextView(this);
    tv.setText(team);/*  ww  w .  j  a v  a  2  s.  c o m*/
    row.addView(tv);
    TextView scoreView = new TextView(this);
    scoreView.setText(Integer.toString(score));
    scoreView.setGravity(Gravity.RIGHT);
    row.addView(scoreView);
    scoreTable.addView(row);
}

From source file:com.manuelpeinado.numericpageindicator.demo.MyPagerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    TextView item = new TextView(container.getContext());
    item.setText(Integer.toString(position + 1));
    item.setTextColor(Color.argb(192, 255, 255, 255));
    item.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 50);
    item.setGravity(Gravity.CENTER);
    item.setBackgroundColor(COLORS[position % COLORS.length]);
    ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    container.addView(item, layoutParams);
    return item;/*from w  ww  . j av a  2 s  .com*/
}

From source file:ca.farrelltonsolar.classic.DayLogCalendar.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    theView = inflater.inflate(R.layout.day_log_calendar, container, false);
    Bundle args = getArguments();/*  w w w . j  ava 2 s . c  o  m*/
    int monthOffset = args != null ? args.getInt(ARG_MONTH) : 0;
    month = DateTime.now().minusMonths(monthOffset).withTimeAtStartOfDay().withDayOfMonth(1);
    adapter = new CalendarAdapter(this.getActivity(), month);
    GridView gridview = (GridView) theView.findViewById(R.id.gridview);
    gridview.setAdapter(adapter);
    gridview.setVelocityScale(5);

    TextView title = (TextView) theView.findViewById(R.id.title);
    title.setText(month.toString("MMMM yyyy"));
    View linearLayout = theView.findViewById(R.id.headerlayout);
    DateTime days = month;

    for (int i = 0; i < 7; i++) {
        int d = ((i + 6) % 7) + 1;
        days = days.withDayOfWeek(d);
        TextView aDay = new TextView(theView.getContext());
        aDay.setText(DateTimeFormat.forPattern("E").print(days));
        aDay.setGravity(Gravity.CENTER);
        aDay.setTextColor(Color.BLACK);
        aDay.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
        ((LinearLayout) linearLayout).addView(aDay);

    }

    return theView;
}