I've to develop an Android application that needs to show data using a similar layout.
I need two parts of screen:
- A layout with a fluid height that vary on resolution of device
- Second layout that show content in a fixed size
How to do this? I've used relativelayout and linearlayout but I haven't found a solution.
Could you help me?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/fixedlayout"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:id="@+id/fluidlayout" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:orientation="vertical"
android:id="@+id/fixedlayout" >
</LinearLayout>
</RelativeLayout>
More efficient solution using LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp" >
</LinearLayout>
</LinearLayout>
For a LinearLayout
set top layout to android:layout_weight="1"
(and height to 0dp
) and bottom layout_height
to either a fixed value or android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FF0000" />
<View
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#00FF00" />
</LinearLayout>