Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set LinearLayout in bottom of FrameLayout programmatically?

I have this code :

         FrameLayout game = new FrameLayout(this);
         LinearLayout gameWidgets = new LinearLayout (this);
         game.addView(gameWidgets);

How to set the LinearLayout in the buttom of the FrameLayout ?

like image 465
Ala Aga Avatar asked Jul 08 '13 09:07

Ala Aga


People also ask

How do you do LinearLayout at the bottom?

If you want to add Buttons to the bottom of your android layout XML file you can achieve it using attribute layout_gravity on LinearLayout or TableRow layout. Below your Parent Layout tag add a LinearLayout or TableRow with attribute android:layout_gravity="bottom".

How do I center a view in FrameLayout?

You can specify the gravity as center_horizontal, center_vertical and center (which centers both horizontally and vertically). On the child views of the LinearLayout you can specify the layout_gravity property, which also supports center_horizontal, center_vertical and center.

Why does FrameLayout hold one view?

FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other.

Is FrameLayout a ViewGroup?

Android Framelayout is a ViewGroup subclass that is used to specify the position of multiple views placed on top of each other to represent a single view screen.


1 Answers

Try this,

FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
    LayoutParams.WRAP_CONTENT,
    LayoutParams.WRAP_CONTENT);

params.gravity = Gravity.BOTTOM;

game.addView(GameWidgets, params); 
like image 107
Donald Zhang Avatar answered Oct 20 '22 15:10

Donald Zhang