Reputation: 398
I a have made a registration form in which i have two buttons.Now what i want is that when the keyboard is displayed the two buttons which are at the bottom should be displayed above the keyboard and not hidden under the keyboard.To achieve this the code i wrote didn't gave me any success.
Xml Code
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:inputType="textPersonName"
style="@style/EditText"
android:hint="@string/firstname"
android:id="@+id/et_first_name" />
<EditText
android:inputType="textPersonName"
style="@style/EditText"
android:hint="@string/lastname"
android:id="@+id/et_last_name" />
<Button
style="@style/EditText"
android:text="@string/country"
android:id="@+id/bt_country" />
<Button
style="@style/EditText"
android:text="@string/gender"
android:id="@+id/bt_gender" />
<EditText
style="@style/EditText"
android:inputType="phone"
android:hint="@string/mobileno"
android:id="@+id/et_mobile_no" />
<EditText
style="@style/EditText"
android:inputType="textEmailAddress"
android:hint="@string/email"
android:id="@+id/et_email" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
style="@style/EditText"
android:id="@+id/bt_reg_cancel"
android:text="@string/cancel"
android:layout_gravity="bottom"
android:layout_weight="1" />
<Button
style="@style/EditText"
android:text="@string/save"
android:id="@+id/bt_reg_save"
android:layout_gravity="bottom"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
Please do help
Upvotes: 3
Views: 4830
Reputation: 5295
In the Android Manifest, give the property android:windowSoftInputMode="adjustResize"
. This will resize your layout when keyboard shows.
So if something is on the bottom, it will show above the keyboard once it shows
"Please can u show me the code with relative layout, it would be very helpfull??? – user3917131 7 mins ago "
Solution :-
2.) Weight Approach :- ScrollView -> 0.7 RelativeLayout -> 0.3 -> In it write your bottom layout and give the property align parent bottom true. In this approach, your scrollview will take only 0.7 of screen as per weight guidelines and the rest by your bottom layout
3.) remove scrollview, instead make it linearlayout. Make Top Parent Relative Layout and give the property align parent bottom true to your bottom layout and the layout above property to your linearlayout
Upvotes: 2
Reputation: 949
You should set leyout_weight of ScrollView to 1 for example. And set leyout_height of LinearLayout to "wrap_content". And that would be nice to set layout_height of ScrollView to 0dp, so LinearLayout can manage it`s heigth.
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<ScrollView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
</ScrollView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
style="@style/EditText"
android:id="@+id/bt_reg_cancel"
android:text="@string/cancel"
android:layout_gravity="bottom"
android:layout_weight="1" />
<Button
style="@style/EditText"
android:text="@string/save"
android:id="@+id/bt_reg_save"
android:layout_gravity="bottom"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
That should do the trick.
Upvotes: 0