I have a EditText
field within a LinearLayout
which is in a scrollview. As long as the ScrollView
is not there the layout_weight="1.0"
lets my EditText
to occupy the remaining screen. But as soon as I wrap the LinearLayout within a ScrollView
, It changes the EditText
to a single line and layout_weight doesn't work.
My complete layout file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="fill_parent" android:orientation="vertical" >
<TextView android:id="@+id/titleTextView"
style="@style/TitleHeaderBarText"
android:text="@string/announcement" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="right" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subject:"
android:textSize="16sp" />
<EditText
android:id="@+id/et_subject"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Announcement:"
android:textSize="16sp" />
<EditText
android:id="@+id/et_announcement"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0" />
<Button
android:id="@+id/btn_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="24sp"
android:paddingRight="24dp"
android:text="Save" />
</LinearLayout>
</ScrollView>
</LinearLayout>
I don't seem to understand what I am doing wrong. Any suggestions please on how to get the EditText to occupy the rest of the screen from within the LinearLayout
which is in a ScrollView
.
Thank you.
EDIT Facing the same problem again and this is my layout.
<?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" >
<TextView android:id="@+id/titleTextView"
style="@style/TitleHeaderBarText"
android:text="@string/login_title" />
<ScrollView
android:id="@+id/sv_weight_tell_us"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/bg_light_radial_pink" >
<LinearLayout
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="12dp"
android:orientation="vertical" >
<TextView
android:id="@+id/login_header"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="Login" />
<TableLayout
android:layout_width="match_parent" android:layout_height="wrap_content"
android:stretchColumns="1" >
<TableRow>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:paddingRight="20dp"
android:text="@string/username" />
<EditText
android:id="@+id/et_username"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/password" />
<EditText
android:id="@+id/et_password"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:inputType="textPassword" />
</TableRow>
<TableRow>
<View/>
<Button
android:id="@+id/btn_login"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/login"
android:padding="12dp" />
</TableRow>
</TableLayout>
<ProgressBar
android:id="@+id/pb_1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:indeterminate="true"
style="?android:attr/progressBarStyleSmall"
android:visibility="invisible" />
<TextView
android:layout_width="wrap_content" android:layout_height="match_parent"
android:layout_weight="1.0" android:gravity="bottom"
android:text="@string/dont_have_Q" />
<TextView
android:id="@+id/tv_sign_up"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="@string/sign_up_" />
</LinearLayout>
</ScrollView>
</LinearLayout>
You need to add the ScrollView attribute android:fillViewport="true"
:
...
<ScrollView
android:id="@+id/sv_weight_tell_us"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/bg_light_radial_pink"
android:fillViewport="true" >
....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With