I add a custom view dynamically,but when I change the parameters (height,width), the view dissapear or if i just add it with the standard parameters it works normally.What's the problem? I'm trying to add the parts of this dynamically and affect new parameters to the parts.
xml code:
<RadioGroup
android:id="@+id/prog"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:layout_gravity="center"
android:layout_margin="10sp"
android:orientation="horizontal"
android:textAlignment="center" >
</RadioGroup>
Implementation code:
bar = (RadioGroup) getView().findViewById(R.id.prog);
int width = bar.getWidth();
RadioGroup.LayoutParams lparams = new RadioGroup.LayoutParams(width / 2,
height);
SegmentedControlButton part = new SegmentedControlButton(getActivity());
part.setLayoutParams(lparams);
bar.addView(part);
with one part it works but with 2 parts it disappears.
I tried to check the value of width and it's 0
but i call the method in OnViewCreated
so normally the view is prepared there.
PS: I use a fragment
UPDATE:
I tried this implementation in OnViewCreated
but still 0
:
ViewTreeObserver vto = bar.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
width = bar.getWidth();
}
});