Reputation: 87
I have a RelativeLayout and a LinearLayout inside a CoordinatorLayout. I want to align the LinearLayout at the bottom of RelativeLayout. but layoutbelow does not work here. I dont know how to implement this.
this is my code
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/top"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:src="@drawable/artboard_signup"
android:scaleType="fitXY"
android:visibility=""
/>
</RelativeLayout>
<LinearLayout
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="170dp">
<LinearLayout
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Top Bootable Antivirus For Your PC?"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8 hours ago"
android:paddingLeft="10dp"/>
</LinearLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
I want the LinearLayout with id bottom to be at the bottom of the RelativeLayout with id top.
Is there anyway that I could achieve this.
Upvotes: 0
Views: 109
Reputation: 10125
Solution:
Just add a <LinearLayout>
inside your <CoordinatorLayout>
as shown below:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
orientation:"vertical">
<RelativeLayout
android:id="@+id/top"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:src="@drawable/artboard_signup"
android:scaleType="fitXY"
android:visibility=""
/>
</RelativeLayout>
<LinearLayout
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="170dp">
<LinearLayout
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Top Bootable Antivirus For Your PC?"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8 hours ago"
android:paddingLeft="10dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Hope it works.
Upvotes: 0
Reputation: 2889
May be this would work. Try it.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/top"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:scaleType="fitXY"
android:src="@drawable/artboard_signup"
android:visibility="" />
<LinearLayout
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="170dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="7"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="15dp"
android:paddingRight="10dp"
android:text="Top Bootable Antivirus For Your PC?" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="8 hours ago" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Upvotes: 0
Reputation: 989
Use RelativeLayout instead of CoordinateLayout and then add the line "android:layout_alignParentBottom="true" " inside LearLayout.
<?xml version="1.0" encoding="utf-8"?>
<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">
<RelativeLayout
android:id="@+id/top"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
app:srcCompat="@drawable/ic_call_black_24dp"
android:scaleType="fitXY"
android:visibility="visible"
/>
</RelativeLayout>
<LinearLayout
android:id="@+id/bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="170dp"
android:layout_alignParentBottom="true">
<LinearLayout
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Top Bootable Antivirus For Your PC?"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8 hours ago"
android:paddingLeft="10dp"/>
</LinearLayout>
</LinearLayout>
Upvotes: 1
Reputation: 251
try to add android:layout_gravity="bottom"
after android:id="@+id/bottom"
Upvotes: 0