Question If I have the following:
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:layout_width="fill_parent" android:layout_height="?" android:orientation="vertical"> <EditText android:layout_width="fill_parent" android:layout_height="?" android:hint="Subject" android:id="@+id/subject" /> <EditText android:layout_width="fill_parent" android:layout_height="?" android:id="@+id/body" /> </LinearLayout> </ScrollView>
How can I get the body (second EditText) to fill the rest of the screen, but still have the scrollview kick in when the contents of the body are too long? Like a height="wrap_content"
and minHeight="fill_parent"
layout_height="fill_parent"
seems to not do anything if you put them in a scrollview
A working example of what I want is the email app compose window
I tried this and the EditText elements act like they are wrap_content and no filling is happening. Just scrolling if you type enough
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <EditText android:layout_width="fill_parent" android:layout_height="fill_parent" layout_weight="1" android:hint="Subject" android:id="@+id/subject" /> <EditText android:layout_width="fill_parent" android:layout_height="fill_parent" layout_weight="1" android:id="@+id/body" /> </LinearLayout> </ScrollView>
fill_parent and match_parent are the same, used when we want the height or width of a view to be as big as its parent view, fill_parent being deprecated. wrap_content is used when we want the view to occupy only as much space as required by it. You may also read : Android UI Layouts.
wrap_content is used to wrap the view according to its actual size. It can be used with layout_height as well as layout_width. If we set layout_height as wrap_content then the height will be the same as the content size and if we set layout_width as wrap_content then the width will be the same as the content size.
FillParent/Match parent: Fill parent is the older version, the updated one is the match parent which takes the entire screen. Wrap Content: Wrap content takes the length of the text and wraps its content. Example: “This is a Wrap Text”. The wrap content starts wrapping from “This” and ends at “text”.
Android layout Width & HeightThis property is used to set the width of the given control. This property has following options:- Wrap_content :- when you set width as wrap_content then it will take the space according to the content. For example. Figure 1.
I ran across a link to the mail app source code in my accepted answer on another question. The answer is simple! Add android:fillViewport="true"
to the <ScrollView...>
and add android:layout_weight="1.0"
to the view you want to take up all the available space. explained in this blogspot
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