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.yktx.check.widget.OldPagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    tab.setText(title);/*from w ww . j  av  a  2 s.  com*/
    tab.setSingleLine();
    tab.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    tab.setGravity(Gravity.CENTER);
    tab.setPadding(0, 3, 0, 0);
    addTab(position, tab);
}

From source file:com.google.sample.beaconservice.ManageBeaconFragment.java

private LinearLayout makeAttachmentTableHeader() {
    LinearLayout headerRow = new LinearLayout(getActivity());
    headerRow.addView(makeTextView("Namespace"));
    headerRow.addView(makeTextView("Type"));
    headerRow.addView(makeTextView("Data"));

    // Attachment rows will have four elements, so insert a fake one here with the same
    // layout weight as the delete button.
    TextView dummyView = new TextView(getActivity());
    dummyView.setLayoutParams(BUTTON_COL_LAYOUT);
    headerRow.addView(dummyView);/*from  w  w  w .j  a  v  a 2 s  .  c  om*/

    return headerRow;
}

From source file:com.umeng.comm.ui.imagepicker.widgets.ViewPagerIndicator.java

/**
 * ??TextView/*  w  ww . j  av a 2 s.  c  o  m*/
 *
 * @param text
 * @return
 */
private TextView generateTextView(String text) {
    TextView tv = new TextView(getContext());
    LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    lp.width = getScreenWidth() / mTabVisibleCount;
    tv.setGravity(Gravity.CENTER);
    tv.setTextColor(COLOR_TEXT_NORMAL);
    tv.setText(text);
    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    tv.setLayoutParams(lp);
    return tv;
}

From source file:com.dotcom.jamaat.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   ww w . j  a  va2  s  .  com
 */
protected TextView createDefaultTabView(Context context) {

    //        TextView textView = new TextView(context);
    //        textView.setGravity(Gravity.CENTER);
    //        textView.setTextSize(context.getResources().getDimension(R.dimen.dimen_9_sp));
    //        textView.setTypeface(Typeface.DEFAULT);

    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    Typeface font = Typeface.createFromAsset(getContext().getAssets(), "fonts/Roboto-Regular.ttf");
    textView.setTypeface(font);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);

    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);
    textView.setAllCaps(false);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(10, padding, 10, padding);

    return textView;

    /*//
            WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            Display display = wm.getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            textView.setWidth(size.x / 3);
    //*/

    //        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(0,20,0,20);
    //
    //        return textView;
}

From source file:com.astuetz.PagerSlidingTabStripPlus.java

/**
 * Add new text view to the linear layout that contains the tab title*
 * @param position of the linear layout in the tabsContainer
 * @param text is the text of the subtitle
 *//*from   www.  j a  v a 2s.  c  om*/
public void addSubtitleAtTab(int position, String text) {
    LinearLayout tab = getSingleTabLayoutAtPosition(position);
    tab.setWeightSum(tab.getChildCount() + 1);
    if (tab.getChildCount() == 1) {
        tab.getChildAt(0).setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1));
    }

    ((TextView) tab.getChildAt(0)).setGravity(Gravity.CENTER_HORIZONTAL);

    TextView newSubTab = new TextView(getContext());
    newSubTab.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0, 1));
    newSubTab.setText(text);
    newSubTab.setGravity(Gravity.CENTER_HORIZONTAL);

    tab.addView(newSubTab);
    updateTabStyles();
}

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

/**
 * ??tab./*w  ww. j av  a  2 s  .c om*/
 *
 * @param tabText the tab text
 * @param fragment the fragment
 */
public void addItemView(String tabText, Fragment fragment) {

    tabItemTextList.add(tabText);
    pagerItemList.add(fragment);

    tabItemList.clear();
    mTabLayout.removeAllViews();

    for (int i = 0; i < tabItemTextList.size(); i++) {
        final int index = i;
        String text = tabItemTextList.get(i);
        TextView tv = new TextView(this.context);
        tv.setTextColor(tabColor);
        tv.setTextSize(tabTextSize);
        tv.setText(text);
        tv.setGravity(Gravity.CENTER);
        tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1));
        tv.setPadding(12, 5, 12, 5);
        tv.setFocusable(false);
        tabItemList.add(tv);
        mTabLayout.addView(tv);
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mViewPager.setCurrentItem(index);
            }
        });
    }

    //?
    AbLogUtil.d(AbSlidingSmoothTabView.class, "addItemView finish");
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);
}

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

/**
 * ??tab.//from  w  w  w . j  a  va 2  s.  c  o m
 *
 * @param tabText the tab text
 * @param fragment the fragment
 */
public void addItemView(String tabText, Fragment fragment) {

    tabItemTextList.add(tabText);
    pagerItemList.add(fragment);

    tabItemList.clear();
    mTabLayout.removeAllViews();

    for (int i = 0; i < tabItemTextList.size(); i++) {
        final int index = i;
        String text = tabItemTextList.get(i);
        TextView tv = new TextView(this.context);
        tv.setTextColor(tabColor);
        tv.setTextSize(tabTextSize);
        tv.setText(text);
        tv.setGravity(Gravity.CENTER);
        tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1));
        tv.setPadding(12, 5, 12, 5);
        tv.setFocusable(false);
        tabItemList.add(tv);
        mTabLayout.addView(tv);
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mViewPager.setCurrentItem(index);
            }
        });
    }

    //?
    ESLogUtil.d(ESSlidingSmoothTabView.class, "addItemView finish");
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);
}

From source file:com.near.chimerarevo.fragments.ProductFragment.java

private void addTitle(String text) {
    TextView title = new TextView(getActivity());
    title.setBackgroundColor(getResources().getColor(R.color.prod_title_color));
    title.setTextColor(getResources().getColor(android.R.color.white));
    title.setTypeface(Typeface.createFromAsset(getActivity().getAssets(), "roboto_light.ttf"));
    title.setTextSize(22);//from w  w w . j  a  va  2 s.  c o  m
    title.setPadding(15, 10, 15, 10);

    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    title.setLayoutParams(params);

    title.setText(text);

    View div = new View(getActivity());
    div.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 2));
    div.setBackgroundColor(getResources().getColor(R.color.prod_title_color));

    lay.addView(title);
    lay.addView(div);
}

From source file:android.view.SpringIndicator.java

private void addTabItems() {
    final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
    tabs = new ArrayList<>();
    for (int i = 0; i < viewPager.getAdapter().getCount(); i++) {
        final TextView textView = new TextView(getContext());
        if (viewPager.getAdapter().getPageTitle(i) != null)
            textView.setText(viewPager.getAdapter().getPageTitle(i));
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        textView.setTextColor(getResources().getColor(textColorId));
        if (textBgResId != 0)
            textView.setBackgroundResource(textBgResId);
        textView.setLayoutParams(layoutParams);
        final int position = i;
        textView.setOnClickListener(new OnClickListener() {
            @Override/*from ww w .  jav a 2  s. c o  m*/
            public void onClick(final View v) {
                if (tabClickListener == null || tabClickListener.onTabClick(position))
                    viewPager.setCurrentItem(position);
            }
        });
        tabs.add(textView);
        tabContainer.addView(textView);
    }
}

From source file:fr.cph.chicago.core.adapter.NearbyAdapter.java

private View handleBikes(final int position, @NonNull final ViewGroup parent) {
    final LayoutInflater vi = (LayoutInflater) parent.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View convertView = vi.inflate(R.layout.list_nearby, parent, false);

    final int index = position - (stations.size() + busStops.size());
    final BikeStation bikeStation = bikeStations.get(index);

    final LinearLayout favoritesData = (LinearLayout) convertView.findViewById(R.id.nearby_results);

    final ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
    imageView.setImageDrawable(/* w ww  . j av  a 2  s. c o m*/
            ContextCompat.getDrawable(parent.getContext(), R.drawable.ic_directions_bike_white_24dp));

    final TextView routeView = (TextView) convertView.findViewById(R.id.station_name);
    routeView.setText(bikeStation.getName());

    final LinearLayout llh = new LinearLayout(context);
    llh.setOrientation(LinearLayout.HORIZONTAL);
    llh.setPadding(line1PaddingColor, stopsPaddingTop, 0, 0);

    final LinearLayout availableLayout = new LinearLayout(context);
    availableLayout.setOrientation(LinearLayout.VERTICAL);

    final LinearLayout.LayoutParams leftParam = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final RelativeLayout availableBikes = new RelativeLayout(context);
    availableBikes.setLayoutParams(leftParam);
    availableBikes.setPadding(line1PaddingColor, 0, 0, 0);

    final RelativeLayout lineIndication = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA);
    int lineId = Util.generateViewId();
    lineIndication.setId(lineId);

    final RelativeLayout.LayoutParams availableParam = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    availableParam.addRule(RelativeLayout.RIGHT_OF, lineId);
    availableParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0);

    final TextView availableBike = new TextView(context);
    availableBike.setText(context.getString(R.string.bike_available_bikes));
    availableBike.setTextColor(ContextCompat.getColor(context, R.color.grey_5));
    availableBike.setLayoutParams(availableParam);
    int availableBikeId = Util.generateViewId();
    availableBike.setId(availableBikeId);

    final RelativeLayout.LayoutParams amountParam = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    amountParam.addRule(RelativeLayout.RIGHT_OF, availableBikeId);

    final TextView amountBike = new TextView(context);
    final String amountBikeText = String.valueOf(bikeStation.getAvailableBikes());
    amountBike.setText(amountBikeText);
    int color = bikeStation.getAvailableBikes() == 0 ? R.color.red : R.color.green;
    amountBike.setTextColor(ContextCompat.getColor(context, color));
    amountBike.setLayoutParams(amountParam);

    availableBikes.addView(lineIndication);
    availableBikes.addView(availableBike);
    availableBikes.addView(amountBike);

    final LinearLayout.LayoutParams leftParam2 = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final RelativeLayout availableDocks = new RelativeLayout(context);
    availableDocks.setLayoutParams(leftParam2);
    availableDocks.setPadding(line1PaddingColor, 0, 0, 0);

    final RelativeLayout lineIndication2 = LayoutUtil.createColoredRoundForFavorites(context, TrainLine.NA);
    int lineId2 = Util.generateViewId();
    lineIndication2.setId(lineId2);

    final RelativeLayout.LayoutParams availableDockParam = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    availableDockParam.addRule(RelativeLayout.RIGHT_OF, lineId2);
    availableDockParam.setMargins(Util.convertDpToPixel(context, 10), 0, 0, 0);

    final TextView availableDock = new TextView(context);
    availableDock.setText(context.getString(R.string.bike_available_docks));
    availableDock.setTextColor(ContextCompat.getColor(context, R.color.grey_5));
    availableDock.setLayoutParams(availableDockParam);
    int availableDockBikeId = Util.generateViewId();
    availableDock.setId(availableDockBikeId);

    final RelativeLayout.LayoutParams amountParam2 = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    amountParam2.addRule(RelativeLayout.RIGHT_OF, availableDockBikeId);

    final TextView amountDock = new TextView(context);
    final String amountDockText = String.valueOf(bikeStation.getAvailableDocks());
    amountDock.setText(amountDockText);
    color = bikeStation.getAvailableDocks() == 0 ? R.color.red : R.color.green;
    amountDock.setTextColor(ContextCompat.getColor(context, color));

    amountDock.setLayoutParams(amountParam2);

    availableDocks.addView(lineIndication2);
    availableDocks.addView(availableDock);
    availableDocks.addView(amountDock);

    availableLayout.addView(availableBikes);
    availableLayout.addView(availableDocks);

    llh.addView(availableLayout);

    favoritesData.addView(llh);

    convertView.setOnClickListener(new NearbyOnClickListener(googleMap, markers, bikeStation.getId(),
            bikeStation.getLatitude(), bikeStation.getLongitude()));
    return convertView;
}