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.stylovid.fastbattery.CurrentInfoFragment.java

private void setSizes(Configuration config) {
    boolean portrait = config.orientation == Configuration.ORIENTATION_PORTRAIT;

    int screenWidth, screenHeight;

    if (android.os.Build.VERSION.SDK_INT < 13) {
        DisplayMetrics metrics = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);

        screenWidth = metrics.widthPixels;
        screenHeight = (int) (metrics.heightPixels * 0.95);
    } else {/* w ww .j a  v  a  2  s. com*/
        screenWidth = (int) (config.screenWidthDp * dpScale);
        screenHeight = (int) (config.screenHeightDp * dpScale);
    }

    int minDimen = Math.min(screenWidth, screenHeight);
    float aspectRatio = (float) screenWidth / screenHeight;

    // System.out.println("...................................................." +
    //                    "\n    config.screenWidthDp: " + config.screenWidthDp +
    //                    "\n    config.screenHeightDp: " + config.screenHeightDp +
    //                    "\n    config figured pixel width: " + screenWidth +
    //                    "\n    config figured pixel height: " + screenHeight +
    //                    "\n    aspectRatio: " + aspectRatio +
    //                    "\n    portrait: " + portrait
    //                    );

    int plugged_icon_height;
    int time_remaining_text_height, until_what_text_height;
    int status_text_height;
    int bu_height, bu_text_height;
    int vital_icon_height, vital_text_height;

    if (portrait) {
        plugged_icon_height = (int) (screenHeight * 0.1);

        time_remaining_text_height = (int) (screenHeight * 0.048);
        until_what_text_height = (int) (screenHeight * 0.032);

        status_text_height = (int) (screenHeight * 0.04);

        bu_height = (int) (screenHeight * 0.14);
        bu_text_height = (int) (screenHeight * 0.035);

        vital_icon_height = (int) (screenHeight * 0.05);
        vital_text_height = (int) (screenHeight * 0.03);
    } else {
        plugged_icon_height = (int) (screenHeight * 0.11);

        time_remaining_text_height = (int) (screenHeight * 0.06);
        until_what_text_height = (int) (screenHeight * 0.04);

        status_text_height = (int) (screenHeight * 0.05);

        bu_height = (int) (screenHeight * 0.18);
        bu_text_height = (int) (screenHeight * 0.045);

        vital_icon_height = (int) (screenHeight * 0.08);
        vital_text_height = (int) (screenHeight * 0.05);
    }

    TextView level = (TextView) view.findViewById(R.id.level);
    level.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, plugged_icon_height);

    View clock = view.findViewById(R.id.clock);
    clock.setLayoutParams(
            new LinearLayout.LayoutParams(plugged_icon_height, ViewGroup.LayoutParams.MATCH_PARENT));

    TextView time_remaining = (TextView) view.findViewById(R.id.time_remaining);
    time_remaining.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, time_remaining_text_height);

    TextView until_what = (TextView) view.findViewById(R.id.until_what);
    until_what.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, until_what_text_height);

    TextView status = (TextView) view.findViewById(R.id.status);
    status.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, status_text_height);

    TextView status_duration = (TextView) view.findViewById(R.id.status_duration);
    status_duration.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, until_what_text_height);

    View plugged_icon = view.findViewById(R.id.plugged_icon);
    plugged_icon.setLayoutParams(
            new LinearLayout.LayoutParams(plugged_icon_height, ViewGroup.LayoutParams.MATCH_PARENT));

    View plugged_spacer = view.findViewById(R.id.plugged_spacer);
    plugged_spacer.setLayoutParams(new LinearLayout.LayoutParams(plugged_icon_height, plugged_icon_height));

    Button bu_button = (Button) view.findViewById(R.id.battery_use_b);
    bu_button.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, bu_height));
    bu_button.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, bu_text_height);

    View temp_icon = view.findViewById(R.id.temp_icon);
    temp_icon.setLayoutParams(new LinearLayout.LayoutParams(vital_icon_height, vital_icon_height));
    TextView temp_text = (TextView) view.findViewById(R.id.temp);
    temp_text.setLayoutParams(new LinearLayout.LayoutParams(0, vital_icon_height, 0.5f));
    temp_text.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, vital_text_height);

    View health_icon = view.findViewById(R.id.health_icon);
    health_icon.setLayoutParams(new LinearLayout.LayoutParams(vital_icon_height, vital_icon_height));
    TextView health_text = (TextView) view.findViewById(R.id.health);
    health_text.setLayoutParams(new LinearLayout.LayoutParams(0, vital_icon_height, 0.5f));
    health_text.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, vital_text_height);

    View voltage_icon = view.findViewById(R.id.voltage_icon);
    voltage_icon.setLayoutParams(new LinearLayout.LayoutParams(vital_icon_height, vital_icon_height));
    TextView voltage_text = (TextView) view.findViewById(R.id.voltage);
    voltage_text.setLayoutParams(new LinearLayout.LayoutParams(0, vital_icon_height, 0.5f));
    voltage_text.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, vital_text_height);

    View current_icon = view.findViewById(R.id.current_icon);
    current_icon.setLayoutParams(new LinearLayout.LayoutParams(vital_icon_height, vital_icon_height));
    TextView current_text = (TextView) view.findViewById(R.id.current);
    current_text.setLayoutParams(new LinearLayout.LayoutParams(0, vital_icon_height, 0.5f));
    current_text.setTextSize(android.util.TypedValue.COMPLEX_UNIT_PX, vital_text_height);

    // When in landscape but close to square, plugged icon gets cramped and cut off; make more room:
    if (!portrait && aspectRatio < 1.32)
        plugged_spacer.setVisibility(View.GONE);
    else
        plugged_spacer.setVisibility(View.INVISIBLE);
}

From source file:cn.com.zzwfang.view.indicator.PagerSlidingTabStrip.java

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

    TextView tab = new TextView(getContext());
    tab.setLayoutParams(getLayoutParams());
    tab.setText(title);/*from  ww w .j  a  v  a2s .  co  m*/
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    tabsContainer.addView(tab);

}

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

/**
 * ??tab./*  w  w  w  .  j a v a 2s. c  o m*/
 *
 * @param tabTexts the tab texts
 * @param fragments the fragments
 */
public void addItemViews(List<String> tabTexts, List<Fragment> fragments) {

    tabItemTextList.addAll(tabTexts);
    pagerItemList.addAll(fragments);

    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);
            }
        });
    }

    //?
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);

}

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

/**
 * ??tab.//from   w w  w  .j a  v a  2s . 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(AbSlidingSmoothFixTabView.class, "addItemView finish");
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);
}

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

/**
 * ??tab./*w w w  .j  ava2  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(ESSlidingSmoothFixTabView.class, "addItemView finish");
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);
}

From source file:com.starshow.app.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)}.//w w  w. j av  a  2  s  . c o  m
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setBackgroundColor(getResources().getColor(R.color.white));
    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);
    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.prateek.eskores.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  va  2  s  .com*/
 */
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);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT);
    params.weight = 0.5f;
    textView.setLayoutParams(params);

    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.example.parkhere.seeker.SeekerProfileVehicleFragment.java

public void getCurrInfo() {
    tag = 1;//  w w  w. ja v a 2 s . c  o m

    Retrofit retrofit = new Retrofit.Builder().baseUrl(Constants.BASE_URL)
            .addConverterFactory(GsonConverterFactory.create()).build();

    RequestInterface requestInterface = retrofit.create(RequestInterface.class);

    ServerRequest request = new ServerRequest();
    request.setOperation(Constants.GET_SEEKER_PROFILE_OPERATION);
    request.setUser(user);
    Call<ServerResponse> response = requestInterface.operation(request);

    response.enqueue(new Callback<ServerResponse>() {
        @Override
        public void onResponse(Call<ServerResponse> call, retrofit2.Response<ServerResponse> response) {
            ServerResponse resp = response.body();

            if (resp.getResult().equals(Constants.SUCCESS)) {
                vehicles = resp.getVehicles();

                TableRow tr_head = new TableRow(myContext);
                tr_head.setBackgroundColor(Color.GRAY);
                tr_head.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
                        TableRow.LayoutParams.WRAP_CONTENT));

                TextView make = new TextView(myContext);
                make.setText("MAKE");
                make.setTextColor(Color.WHITE);
                make.setPadding(5, 5, 5, 5);
                tr_head.addView(make);

                TextView model = new TextView(myContext);
                model.setText("MODEL");
                model.setTextColor(Color.WHITE);
                model.setPadding(5, 5, 5, 5);
                tr_head.addView(model);

                final TextView license = new TextView(myContext);
                license.setText("LICENSE PLATE");
                license.setTextColor(Color.WHITE);
                license.setPadding(5, 5, 5, 5);
                tr_head.addView(license);

                tl.addView(tr_head, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT,
                        TableLayout.LayoutParams.WRAP_CONTENT));

                for (int i = 0; i < vehicles.length; i++) {
                    if (vehicles[i].getDeletedWithHistory() == 1) {
                        continue;
                    }

                    TableRow tr = new TableRow(myContext);
                    tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
                            TableRow.LayoutParams.WRAP_CONTENT));
                    tr.setTag(tag);
                    tag++;
                    tr.setClickable(true);
                    tr.setOnClickListener(clickListener);

                    TextView v_make = new TextView(myContext);
                    v_make.setText(vehicles[i].getMake());
                    v_make.setLayoutParams(new TableRow.LayoutParams(300, 150));
                    tr.addView(v_make);

                    TextView v_model = new TextView(myContext);
                    v_model.setText(vehicles[i].getModel());
                    v_model.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                            TableRow.LayoutParams.WRAP_CONTENT));
                    tr.addView(v_model);

                    TextView v_license = new TextView(myContext);
                    v_license.setText(vehicles[i].getLicensePlate());
                    v_license.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                            TableRow.LayoutParams.WRAP_CONTENT));
                    tr.addView(v_license);

                    tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT,
                            TableLayout.LayoutParams.WRAP_CONTENT));
                }
            }
        }

        @Override
        public void onFailure(Call<ServerResponse> call, Throwable t) {
            Snackbar.make(rootView, t.getLocalizedMessage(), Snackbar.LENGTH_LONG).show();
        }
    });
}

From source file:com.runtai.pullupsuspension.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)}./*ww  w.  j  a  v a 2 s. c o  m*/
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    //        textView.setGravity(Gravity.CENTER);
    textView.setGravity(17);
    //        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTextSize(2, 12.0F);
    textView.setTypeface(Typeface.DEFAULT);
    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(true);
    //
    //        int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    //        textView.setPadding(padding, padding, padding, padding);
    if (Build.VERSION.SDK_INT >= 11) {
        TypedValue localTypedValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, localTypedValue,
                true);
        textView.setBackgroundResource(localTypedValue.resourceId);
    }
    if (Build.VERSION.SDK_INT >= 14) {
        textView.setAllCaps(true);
        int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
        textView.setPadding(padding + 30, padding, padding + 30, padding);
    }
    return textView;
}

From source file:com.adithyaupadhya.uimodule.roundcornerprogressbar.BaseRoundCornerProgressBar.java

private void previewLayout(Context context) {
    setGravity(Gravity.CENTER);/*  w  ww .  j  a v a 2 s  .  com*/
    TextView tv = new TextView(context);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    tv.setLayoutParams(params);
    tv.setGravity(Gravity.CENTER);
    tv.setText(getClass().getSimpleName());
    tv.setTextColor(Color.WHITE);
    tv.setBackgroundColor(Color.GRAY);
    addView(tv);
}