Example usage for android.widget TextView setLayoutParams

List of usage examples for android.widget TextView setLayoutParams

Introduction

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

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:com.scooter1556.sms.android.presenter.SettingsItemPresenter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());
    view.setLayoutParams(new ViewGroup.LayoutParams(GRID_ITEM_WIDTH, GRID_ITEM_HEIGHT));
    view.setFocusable(true);//from   ww  w. j a  v a 2s .c om
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(ContextCompat.getColor(parent.getContext(), R.color.primary));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    return new ViewHolder(view);
}

From source file:com.scooter1556.sms.androidtv.presenter.MediaFolderPresenter.java

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());
    view.setLayoutParams(new ViewGroup.LayoutParams(GRID_ITEM_WIDTH, GRID_ITEM_HEIGHT));
    view.setFocusable(true);/*w  w  w  .  j av  a  2  s. com*/
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(ContextCompat.getColor(parent.getContext(), R.color.default_background));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    return new ViewHolder(view);
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.FeedRefObj.java

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();/*from   ww  w.j  av  a 2  s. c o m*/
    byte[] raw = obj.getRaw();

    TextView view = new TextView(context);
    view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    String feedName = content.optString(FEED_ID);
    view.setText(feedName);
    view.setBackgroundColor(Feed.colorFor(feedName));
    frame.addView(view);
}

From source file:com.windnow.StationTextActivity.java

@SuppressLint("RtlHardcoded")
private void printTableRow(String line) {
    TableLayout tl = (TableLayout) findViewById(R.id.tableLayout);

    String[] words = line.split("&/");
    TableRow tr = new TableRow(this);
    TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);/*w w  w  . j ava  2  s .com*/
    params.gravity = Gravity.FILL_HORIZONTAL;
    tr.setLayoutParams(params);

    TableRow.LayoutParams tvParams = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
            TableRow.LayoutParams.WRAP_CONTENT);
    tvParams.setMargins(0, 0, 6, 0);

    for (int i = words.length - 1; i >= 0; i--) {
        TextView txv = new TextView(this);
        txv.setLayoutParams(tvParams);
        txv.setText(words[i]);
        txv.setGravity(i == 0 ? Gravity.LEFT : Gravity.LEFT);
        tr.addView(txv, 0);
    }
    tl.addView(tr);
}

From source file:com.chess.genesis.dialog.GamePoolDialog.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle("Game Pool Info");
    setBodyView(R.layout.dialog_gamepool);
    setButtonTxt(R.id.cancel, "Close");

    final TableLayout table = (TableLayout) findViewById(R.id.layout01);
    final LayoutParams layout = (TableRow.LayoutParams) findViewById(R.id.left).getLayoutParams();

    for (final PoolDataItem item : data) {
        final TableRow row = new TableRow(context);

        TextView txt = new TextView(context);
        txt.setLayoutParams(layout);
        txt.setText(item.gametype);//from  w  w  w.  j  ava  2 s  .c  o  m
        row.addView(txt);

        txt = new TextView(context);
        txt.setText(item.time);
        row.addView(txt);

        table.addView(row);
    }
}

From source file:com.art2cat.dev.moonlightnote.controller.settings.CommonSettingsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    if (getArguments() != null) {
        mType = getArguments().getInt("type");
    }/*from www.  j  a v a2  s . c  om*/
    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    linearLayout.setLayoutParams(params);
    ScrollView scrollView = new ScrollView(getActivity());
    scrollView.setLayoutParams(params);
    linearLayout.addView(scrollView);
    TextView textView = new TextView(getActivity());
    textView.setLayoutParams(params);
    int padding = getResources().getDimensionPixelOffset(R.dimen.padding);
    textView.setPadding(padding, padding, padding, padding);
    switch (mType) {
    case Constants.FRAGMENT_ABOUT:
        textView.setGravity(Gravity.CENTER);
        textView.setText(getContent());
        getActivity().setTitle(R.string.settings_about);
        break;
    case Constants.FRAGMENT_LICENSE:
        textView.setGravity(Gravity.CENTER);
        textView.setText(getContent());
        getActivity().setTitle(R.string.settings_license);
        break;
    case Constants.FRAGMENT_POLICY:
        textView.setGravity(Gravity.START);
        textView.setText(getContent());
        getActivity().setTitle(R.string.settings_policy);
        break;
    }
    setHasOptionsMenu(true);
    scrollView.addView(textView);
    return linearLayout;
}

From source file:com.jia.blossom.viewpageindicator.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 w  w  w  .j  a v  a2  s  .c o  m*/
    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.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);//w  w  w.  ja  v a2  s.c o  m
    tv.setTextSize(18);
    tv.setPadding(0, 5, 0, 5);
    tv.setText(text);
    return tv;
}

From source file:com.krg.ParallaxScrollView.sample.PagerViewBackgroundActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Create ParallaxScrollView, which will eventually be the container for everything.
    ParallaxScrollView parallaxScrollView = new ParallaxScrollView(this);
    parallaxScrollView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // Create the Background View, a ViewPager.
    ViewPager backgroundViewPager = new ViewPager(this);
    backgroundViewPager.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 600));
    ImageAdapter adapter = new ImageAdapter(this);
    backgroundViewPager.setAdapter(adapter);

    // Create the Contents View.
    LinearLayout contentView = new LinearLayout(this);
    contentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    contentView.setBackgroundColor(0xffffffff);
    int padding = getResources().getDimensionPixelSize(R.dimen.content_padding);
    contentView.setPadding(padding, padding, padding, padding);
    TextView textView = new TextView(this);
    textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    textView.setText(R.string.starry_night);
    float textSize = getResources().getDimension(R.dimen.content_text_size);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    contentView.addView(textView);//w  ww .java  2s .  c om

    // Make the ParallaxScrollView aware of the Background, Content, and Header Views, and set the content of
    // this view to the ParallaxScrollView.
    parallaxScrollView.setBackgroundView(backgroundViewPager);
    parallaxScrollView.setContentView(contentView);
    setContentView(parallaxScrollView);
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.IMObj.java

public void render(Context context, ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();/*from w  w  w  .ja  va  2s .  c om*/
    TextView valueTV = new TextView(context);
    valueTV.setText("IM:" + content.optString(TEXT));
    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
    frame.addView(valueTV);
}