android - Change child views to fit parent's width when added dynamically -


i have custom view add child views dynamically.

when each child added, need recalculate size of views can fit parent's width

for example: if have textview:

<textview xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.5" android:gravity="center" android:padding="8dp" android:clickable="true" android:textcolor="#666666" android:visibility="visible"/> 

if add 3 of these horizontal linearlayout within xml correctly sizes 3 views total widths match parent.

but want inflate them 1 @ time , add them can reuse elsewhere in code if want different number of textviews in layout.

when this, total width less parent, , can't views resize when new 1 added.

here's inflate view:

layout = (linearlayout) inflater.inflate(r.layout.segmented_control, this);  textview item = (textview) inflater.inflate(r.layout.segmented_control_item, null); 

change width match_parent, think need keep weight. pass parent layout inflater.

layout = (linearlayout) inflater.inflate(r.layout.segmented_control, this);  textview item = (textview) inflater.inflate(r.layout.segmented_control_item, layout, false); layout.addchild(item); 

i'm not sure if works right away, might need experiment little layout paramters.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -