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">
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.
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.
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.
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.
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>
Try using a RelativeLayout
with android:layout_alignParentBottom
and android:layout_centerHorizontal
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With