Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

3 layouts - middle is flexible

I need the following thing:

3 layouts:

  1. Header
  2. Content
  3. Footer

Header must be on the top footer must be sticked to the bottom (android:layout_alignParentBottom="true").

But how to make middle to occupy the whole other screen? Thanks.

like image 940
Volodymyr Avatar asked Jan 23 '26 06:01

Volodymyr


2 Answers

Here is my solution (with android:layout_weight and ScrollView):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="#DDDDDD"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Header"
        tools:ignore="HardcodedText" />
</LinearLayout>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="3" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Content"
        tools:ignore="HardcodedText" />

</ScrollView>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="#DDDDDD"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Footer"
        tools:ignore="HardcodedText" />

</LinearLayout></LinearLayout>

And the result picture :

enter image description here

like image 107
lopez.mikhael Avatar answered Jan 24 '26 21:01

lopez.mikhael


Hi Use the following lines

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:text="Button" >

        <Button
            android:id="@+id/button2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Header" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
       android:layout_above="@+id/linearfooter"
       android:layout_below="@+id/button1"
        android:background="@android:color/darker_gray"
        >
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearfooter"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Button" >

        <Button
            android:id="@+id/button2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="footer" />
    </LinearLayout>

</RelativeLayout>

hope this helps you. Reference Image

like image 27
itsrajesh4uguys Avatar answered Jan 24 '26 22:01

itsrajesh4uguys