简体   繁体   中英

Specify Width as 0dp with weight in android

I have textview for which i want to use weight as well as width, but i want to pass width as 0dp, if i set width in layout params as 0, it does not render on screen.

How can i set width as 0dp dynamically through code

I even tried giving width as LayoutParams.Wrap_Content, but that also hasn't worked

LinearLayout.LayoutParams tv_params_level = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 0.1f);

If you set the width of the TextView via xml to 0dp you must set then its weight to 1 or other value greater than 0. To set the width programatically:

LinearLayout.LayoutParams tv_params_level = new LinearLayout.LayoutParams(0,
    LayoutParams.WRAP_CONTENT, 1.0);

Then set this layout parameteres to your TextView:

tv.setLayoutParams(tv_params_level);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM