ScrollView hides bottom Linear Layout
I have开发者_如何学C the following XML layout in my android application, using ScrollView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent">
<TextView.../>
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout1">
<CheckBox ...>
<requestFocus></requestFocus>
</CheckBox>
<CheckBox ..></CheckBox>
</LinearLayout>
<ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" >
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:text="Block Type:" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<RadioGroup android:orientation="horizontal" android:id="@+id/inputType" android:layout_width="wrap_content" android:layout_height="wrap_content">
<RadioButton android:id="@+id/btCall" android:paddingRight="10px" android:text="Call" android:layout_height="wrap_content" android:layout_width="wrap_content" android:checked="true"></RadioButton>
<RadioButton android:id="@+id/btSMS" android:paddingRight="10px" android:text="SMS" android:layout_height="wrap_content" android:layout_width="wrap_content"></RadioButton>
<RadioButton android:id="@+id/btBoth" android:paddingRight="10px" android:text="Call + SMS" android:layout_height="wrap_content" android:layout_width="wrap_content"></RadioButton>
</RadioGroup>
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/chooseContactButton" android:text="Choose from contacts..."></Button>
<TextView android:text="Name:" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPersonName" android:id="@+id/inputName">d</EditText>
<TextView android:text="Number:" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="phone" android:id="@+id/inputNumber"></EditText>
<TextView android:text="SMS to send:" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:text="I'm busy right now." android:inputType="textMultiLine" android:layout_width="match_parent" android:layout_height="wrap_content" android:minLines="3" android:enabled="false" android:id="@+id/inputMsg"></EditText>
</LinearLayout>
</ScrollView>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout2" android:layout_gravity="bottom">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/okButton" android:text="Save" android:width="150px" android:visibility="gone"></Button>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/updateButton" android:text="Update" android:width="150px" android:visibility="gone"></Button>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/removeButton" android:text="Remove" android:width="150px" android:visibility="gone"></Button>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/cancelButton" android:text="Cancel" android:width="150px"></Button>
</LinearLayout>
</LinearLayout>
The Views above ScrollView freeze fine & the view scrolls good enough. The problem is that the LinearLayout containing Buttons is thrown off the view. It cannot be seen.
Any help is greatly appreciated. Thanks.
On the ScrollView, try changing android:layout_height
to "fill_parent"
adding android:layout_weight="1"
.
This should make the ScrollView set its height to the gap between your set of buttons and the other views above it.
Also, try not to set the height of the ScrollView to "wrap_content", it doesn't make sense as the whole point of it is to scroll through content (within a fixed height).
Why don't you use Relative Layout and set the last linear layout (linearLayout2) as parent bottom and scroll view above this linear layout.
精彩评论