How to achieve alignParentBottom = "true" property in LinearLayout

If I want to set the image at the bottom of any screen, we can use android:layout_alignParentBottom="true" in the relative layout. But for some reason I must use LinearLayout. Other buttons (button, image button, list) are also displayed on the screen. I want to place an image at the bottom of the screen. Whatever the situation, the user will be able to see this image at the bottom of the screen. How to achieve alignParentBottom="true" property in LinearLayout. See the following xml sample. I use example1.xml, but I want to look at the file from example2.xml too

example1.xml

enter image description here

  <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="40dip" android:background="#ffffff" android:textColor="#000000" android:text="I am sunil" android:gravity="bottom"/> </LinearLayout> 

example2.xml

 < ?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="40dip" android:background="#ffffff" android:textColor="#000000" android:text="I am sunil" android:layout_alignParentBottom="true"/> </RelativeLayout> 

thanks

+7
source share
2 answers

Assuming you have a gallery view and list, you can add weight to one of them, which means it will grow as much as possible. If you give weight to more than one kind, they will proportionally distribute the extra space.

For example, add to your gallery and listview android:layout_weight="1"

+1
source

You can use gravity="bottom" for LinearLayout .

For more information about Gravity property, see here.

Here is the sample code. Try the following:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="bottom"> <TextView android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="40dip" android:background="#ffffff" android:textColor="#000000" android:text="I am sunil" android:gravity="bottom"/> </LinearLayout> 

Use gravity="bottom" for LinearLayout instead of TextView .

0
source

All Articles