android - How can i set inflated view width, half of it's parent? -


i inflate view in method:

public tabviewholder oncreateviewholder(viewgroup parent, int viewtype){     view view = layoutinflater.from(parent.getcontext()).inflate(r.layout.tabs_layout, parent, false);     return new tabviewholder(view); } 

because of "false", linearlayout doesn't attach it's parent therefore there no parent , can't use layer_weight (i tested view.getparent(). returns null). because when use layer_weight in combination "layer_width = 0dip", linearlayout disappears.

if use "true" third parameter(view.getparent() returns parent), error:

"the specified child has parent. must call removeview() on child's parent first.".

this parent:

<android.support.v7.widget.recyclerview android:id="@+id/tabbar" style="@style/tabbar"/> 

and parent style:

<style name="tabbar">      <item name="android:layout_width">match_parent</item>      <item name="android:layout_height">0dip</item>      <item name="android:layout_weight">0.1</item>      <item name="android:weightsum">1</item>      <item name="android:background">@color/headerbg</item> </style> 

and linearlayout, child style:

<style name="tablayout">      <item name="android:layout_width">0dip</item>      <item name="android:layout_height">match_parent</item>      <item name="android:layout_weight">0.5</item>      <item name="android:orientation">horizontal</item>      <item name="android:gravity">center_vertical</item>  </style> 

and grandchild, textview:

<style name="tabitem">      <item name="android:layout_width">wrap_content</item>      <item name="android:layout_height">wrap_content</item> </style> 

how can set linearlayout width, half of it's parent?

appreciate in advance.

i used way achieve goal.

i sent recyclerview, parent, parameter tabbaradapter inflates linearlayout, child, , in adapter, set linearlayout's width half width of recyclerview in oncreateviewholder method.

view.getlayoutparams().width = tabbar.getwidth()/2; 

i think, against "loose coupling" (i wanted separate styles code completely).


Comments