guest86
guest86

Reputation: 2956

Android layout problem

I'm trying to create a simple layout but can't find a propper way to do it. Layout should have 3 elements: TextView on top, EditText (with scrollview) in the middle and button on bottom. I made this code:

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

  <LinearLayout android:layout_weight="0.97"
  android:layout_height="wrap_content"
  android:layout_width="fill_parent"
  android:id="@+id/linearLayout18"
  android:orientation="vertical">
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"         
        android:text="Text:"
        android:gravity="center_vertical"/>

    <ScrollView android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <EditText 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:id="@+id/txtMessage"
        android:text=""/>

    </ScrollView>
    </LinearLayout>
    <LinearLayout
    android:layout_weight="0.03"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:id="@+id/linearLayout1"
    android:orientation="vertical">
        <Button 
        android:text="Next"
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />       
    </LinearLayout>
</LinearLayout>

But it gives me layout like this: Layout As you can see the problem is that EditText won't take all available vertical space (all the way to button). How to solve this?

Upvotes: 0

Views: 275

Answers (3)

Archan Desai
Archan Desai

Reputation: 206

Try this ....This is perfect ...I am tested it in my android studio.....This is same layout as you want....

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

    <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Text:"
            android:id="@+id/textview1"
            android:layout_alignParentTop="true"/>


        <ScrollView android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:fillViewport="true"
            android:layout_above="@id/btn"
            android:layout_below="@id/textview1">

            <EditText
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:id="@+id/txtMessage"
                android:text=""/>

        </ScrollView>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/txtMessage"
        android:id="@+id/btn"
        android:text="Next"
        android:layout_alignParentBottom="true"/>

    </RelativeLayout>

Upvotes: 0

Niranj Patel
Niranj Patel

Reputation: 33258

try relativelayout instead of linear here is samle code

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

  <RelativeLayout android:layout_height="wrap_content"
  android:layout_width="fill_parent"
  android:id="@+id/linearLayout18" android:layout_alignParentTop="true">
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"         
        android:text="Text:"
         android:id="@+id/textMessage"
        android:gravity="center_vertical" android:layout_alignParentTop="true"/>

    <ScrollView android:layout_width="fill_parent"
    android:layout_below="@+id/textMessage" android:layout_above="@+id/button1" android:scrollbars="horizontal|vertical" android:layout_height="fill_parent" android:fillViewport="true">

    <EditText 
        android:id="@+id/txtMessage"
        android:text="" android:layout_height="fill_parent" android:layout_width="fill_parent"/>

    </ScrollView>


        <Button 
        android:text="Next"
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/>       
    </RelativeLayout>
</RelativeLayout>

Upvotes: 0

Tanmay Mandal
Tanmay Mandal

Reputation: 40198

Just use android:fillViewport="true" in your ScrollView

Upvotes: 1

Related Questions