Align a LinearLayout at the bottom of a RelativeLayout
Align a LinearLayout at the bottom of a RelativeLayout
I have these nested layouts and i want to put a LinearLayout anchored to the bottom (internally) of the first RelativeLayout but i don't know how to do it. Can someone help me? I want something like this: https://imgur.com/eCCYS8Q
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    tools:context=".MainActivity">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:orientation="vertical"
        android:weightSum="1">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.65"
            android:background="@drawable/background_gradient">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            </LinearLayout>
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.35">
        </RelativeLayout>
    </LinearLayout>
</RelativeLayout>
I added an image of how the layout should be
– Diablo3000
Jun 30 at 18:26
                                4 Answers
                                4
                        
To make layout_weight work properly set android:layout_height="0dp" for both relative layouts    
layout_weight
android:layout_height="0dp"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.65"
        android:background="@color/colorPrimary">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_marginTop="10dp"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_height="match_parent"
            android:background="@color/colorAccent">
        </LinearLayout>
    </RelativeLayout>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.35"
        android:background="@color/colorPrimaryDark">
    </RelativeLayout>
</LinearLayout>
change 10dp to whatever suits you. 
I set the colors just to distinguish the layouts
It worked, thank you very much
– Diablo3000
Jul 1 at 0:13
If you want to align a view to the bottom of a relative layout you need to use 
    android:layout_alignParentBottom="true"
android:layout_alignParentBottom="true"
in the view that is going to be stuck at the bottom of the relative
It doesn't work properly
– Diablo3000
Jun 30 at 18:33
Align LinearLayout to the bottom using id.
take the id of relative layout and then align LinearLayout  to the bottom at the end of relative layout id.
Since you need weighttoo in your UI so This will work for you
weight
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:orientation="vertical"
    android:weightSum="1">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.65"
        android:background="@drawable/background_gradient">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_height="wrap_content">
        </LinearLayout>
    </RelativeLayout>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.35">
    </RelativeLayout>
</LinearLayout>
                                            
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Add id to each view and then explain the problem. Question is not clear
– mark922
Jun 30 at 18:22