Reputation: 599
I'm using 2 inner Linearlayouts to divide my screen into 2 sections. It looks like this:
The first inner Layout has a TextView and a Button. The second one has a ImageView and also a Button. Now I want to get the same height for the TextView and ImageView without setting a fix value for layout_height. The left button should also be in line with the right button.
Here is my xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="de.dk.masterfi.ActMain">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="280dp"
android:background="@drawable/border"
android:padding="10dp"
android:text="@string/welcome"/>
<Button android:id="@+id/button2" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Favoriten"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="280dp" android:src="@drawable/training"/>
<Button android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="Hauptmenü"/>
</LinearLayout>
Upvotes: 2
Views: 1085
Reputation: 1286
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_trail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
tools:context="com.nividbharat.educompanion.activities.TrailActivity">
<RelativeLayout
android:id="@+id/relLayout1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="8dp"
android:layout_marginTop="16dp"
android:layout_weight="0.5"
android:background="@android:color/black"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/button1"
android:background="@android:color/holo_red_dark" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button1" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/relLayout2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="16dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:layout_weight="0.5"
android:background="@android:color/black">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/button2"
android:background="@android:color/holo_red_dark" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Button2" />
</RelativeLayout>
</LinearLayout>
This is how the preview of the layout look like,
Upvotes: 0
Reputation: 852
Change your xml to
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="de.dk.masterfi.ActMain">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/border"
android:padding="10dp"
android:text="@string/welcome"/>
<Button android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Favoriten"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:src="@drawable/training"
android:layout_weight="1"/>
<Button android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hauptmenü"/>
</LinearLayout>
</LinearLayout>
Upvotes: 0
Reputation: 19223
try this, note the android:layout_weight="1"
attribute for TextView
and ImageView
:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="de.dk.masterfi.ActMain">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/border"
android:padding="10dp"
android:text="@string/welcome"/>
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Favoriten"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:src="@drawable/training"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hauptmenü"/>
</LinearLayout>
</LinearLayout>
Upvotes: 2