How to place bottom and center of Android page layout?

I am using a layout and want to display the view in the center and bottom of the page. I use the following code, but it remains in the lower left corner when displayed on the tablet. how to make it a center.

<LinearLayout android:layout_height="wrap_content" android:background="@color/black" android:id="@+id/ll_bookmarkslistad" android:layout_width="fill_parent" android:gravity="center_horizontal|bottom" android:layout_gravity="bottom|center_horizontal"> 
+8
android android-layout
source share
3 answers

What you need to do is have this LinearLayout that you placed inside the RelativeLayout. The relative layout preferably matches your root location with fill_parent for height, as it should reach the bottom.

then add this to your LinearLayout instead of gravity:

 android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" 

Example:

 <?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"> <LinearLayout android:layout_height="wrap_content" android:background="@color/black" android:id="@+id/ll_bookmarkslistad" android:layout_width="fill_parent" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" > <!-- stuff inside layout --> </LinearLayout> </RelativeLayout> 
+17
source share

Try using RelativeLayout with android:layout_alignParentBottom and android:layout_centerHorizontal

+1
source share

@pink_candy does not use gravity in LinearLayout, if you use it, it is applicable to all child views in this LinearLayout. If you want any particular view to be aligned, then set the layout_gravity parameter only for that view, the view can be a button, image, custom view, or even another layout.

+1
source share

All Articles