Reputation: 7581
The app has a screen that needs at the bottom a button bar. Above are a few text views and 1 editview.
When the user starts editing, the software keyboard becomes visible. I would like the buttons to move up and always be visible. The rest of the views should shrink.
Normally I would expect the below code to work. I tried many options, e.g. with a RelativeLayout as top layout manager.
==> The result is that the button bar is gone!
When I remove the Scrollview, then the buttons bar is visible again.
Why does the button bar disappear? In the designer it is visible.
My first series of attempts (that I use in other screens) uses a RelativeLayout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="horizontal" >
<ScrollView
android:id="@+id/layout_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_above="@id/bottom_buttons"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="7dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Notes"
android:textStyle="bold" />
<EditText
android:id="@+id/the_edit_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Notes"
android:minLines="3"
android:text="" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some static text"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some dynamic text />
</LinearLayout>
<TextView
android:id="@+id/abc_explanation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_vertical"
android:text="" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/bottom_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<Button
android:layout_alignParentBottom="true"
android:id="@+id/save_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button ... 2>
<Button ... 3>
</LinearLayout>
</RelativeLayout>
In my AndroidManifest.xml I use normally:
<activity
android:name="xy.organisation.app.MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize"
android:configChanges="keyboard|keyboardHidden|orientation" >
My second series of attempts is using a LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/layout_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="7dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Notes"
android:textStyle="bold" />
<EditText
android:id="@+id/the_edit_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Notes"
android:minLines="3"
android:text="" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some static text"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some dynamic text />
</LinearLayout>
<TextView
android:id="@+id/abc_explanation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_vertical"
android:text="" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/bottom_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="5dp"
android:layout_weight="0"
android:orientation="horizontal">
<Button
android:id="@+id/save_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button ... 2>
<Button ... 3>
</LinearLayout>
</LinearLayout>
Upvotes: 0
Views: 809
Reputation: 9225
I tried your code:
Below code is working fine:--
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="horizontal"
tools:context=".RelativeActivity"
android:fillViewport="true">
<ScrollView
android:id="@+id/layout_scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="7dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Notes"
android:textStyle="bold" />
<EditText
android:id="@+id/the_edit_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Notes"
android:minLines="3"
android:text="" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some static text"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some dynamic text" />
</LinearLayout>
<TextView
android:id="@+id/abc_explanation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_vertical"
android:text="" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/bottom_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="5dp"
android:layout_weight="0"
android:orientation="horizontal">
<Button
android:id="@+id/save_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save1" />
<Button
android:id="@+id/save_button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save2" />
<Button
android:id="@+id/save_button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save3" />
</LinearLayout>
</LinearLayout>
Please check your AndroidManifest.xml
.
If there is android:windowSoftInputMode="adjustPan"
under your activity like below:
<activity android:name=".RelativeActivity"
android:windowSoftInputMode="adjustPan"/>
Remove android:windowSoftInputMode="adjustPan"
from AndroidManifest file under your activity. Because of adjustPan your bottom buttons are disappear when keyboard is open.
I hope its work for you.
Upvotes: 1
Reputation: 7114
You have given weight 0 to the linear layout of the buttons. Removing that will fix the issue. Also add 0dp
height to ScrollView
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="@+id/layout_scrollview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="7dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Notes"
android:textStyle="bold" />
<EditText
android:id="@+id/the_edit_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Notes"
android:minLines="3"
android:text="" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some static text"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some dynamic text />
</LinearLayout>
<TextView
android:id="@+id/abc_explanation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_vertical"
android:text="" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/bottom_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<Button
android:id="@+id/save_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
<Button ... 2>
<Button ... 3>
</LinearLayout>
Relative Layout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="@+id/layout_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_buttons"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="7dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="Notes"
android:textStyle="bold"/>
<EditText
android:id="@+id/the_edit_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Notes"
android:minLines="3"
android:text=""/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some static text"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some dynamic text"/>
</LinearLayout>
<TextView
android:id="@+id/abc_explanation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_vertical"
android:text=""/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_alignParentBottom="true"
android:id="@+id/bottom_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<Button
android:id="@+id/save_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save"/>
<Button
android:id="@+id/save_button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save"/>
<Button
android:id="@+id/save_button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save"/>
</LinearLayout>
Upvotes: 1