Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to place a view bottom and center of the page android layout?

i am using a layout and want to display the view at the center and bottom of the page. am using the following code but it stays at the bottom left not center when displayed on tablet. how to make it 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">
like image 622
cavallo Avatar asked Nov 17 '11 12:11

cavallo


People also ask

How do you put a view at the bottom?

Use LinearLayout in your root Layout ( android:orientation="vertical" ) The main attribute is ndroid:gravity="bottom" , let the child View on the bottom of Layout.

How do you put a view to the bottom of a linear layout?

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.

How do I center a view in relative layout android?

Centering Views Previously, to center a view in a RelativeLayout you would write centerInParent=true. Constraint Layout instead allows centering in-between views and the parent. Constrain the start to the parent's start and the end to the parent's end. This will center the view horizontally.

How do you place a button at the bottom of the screen in android?

From Settings, go to System, Gestures, and then tap System Navigation. Gesture navigation will be selected by default, but you can tap 3-button navigation to make buttons appear at the bottom of your screen.


2 Answers

What you need to do is to have this LinearLayout of yours put inside a RelativeLayout. The relative layout is preferably your root layout with fill_parent for height as it must reach the bottom.

then add this to your LinearLayout instead of the 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>
like image 67
J.G.Sebring Avatar answered Oct 17 '22 20:10

J.G.Sebring


Try using a RelativeLayout with android:layout_alignParentBottom and android:layout_centerHorizontal

like image 25
Macarse Avatar answered Oct 17 '22 19:10

Macarse