Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Linear Layout - How to Keep Element At Bottom Of View?

I have a TextView which I want to pin at the bottom of a landscape activity that is using LinearLayout with vertically arranged elements.

I have set android:gravity="bottom" on the text view, but it still likes to be just below the last element of the LinearLayout exactly what I do not want it to do.

Any suggestions?

like image 451
Androider Avatar asked Mar 24 '11 20:03

Androider


People also ask

How do I fix the bottom Layout on my android?

You can set the layout_height="0dp" of your header, footer and ScrollView and define a layout_weight . Just play around with the values until you find out which works best. The resulting heights of header and footer would dynamically change with the screensize.

Is linear Layout better than constraint Layout?

So at the rendering, it doesn't have to calculate a lot just render with one onMeasure() method call. That is why the linear layout is more efficient in terms of performance.

How do I change the position of a button in linear Layout?

You can set the android:layout_weight='1' and both buttons will share the screen equally(side by side) or if you want the extra space between them, you can place a button each in a linear layout and set the android:layout_gravity to left and right for each.


1 Answers

You will have to expand one of your upper views to fill the remaining space by setting android:layout_weight="1" on it. This will push your last view down to the bottom.

Here is a brief sketch of what I mean:

<LinearLayout android:orientation="vertical">     <View/>     <View android:layout_weight="1"/>     <View/>     <View android:id="@+id/bottom"/> </LinearLayout> 

where each of the child view heights is "wrap_content" and everything else is "fill_parent".

like image 57
Matthew Willis Avatar answered Oct 13 '22 18:10

Matthew Willis