1
votes

I have frame layout and inside of it linear layout with four buttons. When i write in xml works great but i want to write in java code.

THIS WORKS

<FrameLayout ...
<LinearLayout   
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" 
    android:layout_gravity="bottom">
    <ImageButton
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <ImageButton
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <ImageButton
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />
</LinearLayout>
</FrameLayout>

BUT THIS DOESN't WORK

tbr = new LinearLayout(getBaseContext());
LinearLayout.LayoutParams pa = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
pa.gravity = Gravity.BOTTOM; ///??
tbr.setLayoutParams(pa);

FrameLayout fl = findbyid... f1.addView(tbr);

1
What do you mean by "doesn't work"? If you mean that the child views are not shown, it is because you haven't added them.Jong
I mean that doesn't get down ...Stay at the top of screenrikkima
It doesn't have any contained views, so how can you tell? Try to add some views inside.Jong
i didn't paste all code but i add four buttons which i see on the screen well but not at the bottomrikkima

1 Answers

1
votes

Try:

FrameLayout.LayoutParams pa = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,FrameLayout.LayoutParams.WRAP_CONTENT);
pa.gravity=80;