Android soft input keypad pushes buttons up which overlap other views - android

I have a button aligned to the bottom of my Relative Layout which I want to be pushed up when soft keypad is shown, but I don't want it to overlap other views, any hints?
I have the following layout(XML):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_app" >
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/Button01"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="02dp"
android:background="#drawable/options_bg" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignLeft="#+id/spinner1"
android:layout_below="#+id/textView6"
android:layout_marginTop="03dp"
android:scaleType="centerCrop" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageView1"
android:layout_below="#+id/spinner1"
android:layout_marginLeft="03dp"
android:layout_toRightOf="#+id/imageView1"
android:text="Date"
android:textColor="#002f44"
android:textSize="18sp" />
<Button
android:id="#+id/button2"
android:layout_width="170dp"
android:layout_height="30dp"
android:layout_alignLeft="#+id/textView1"
android:layout_alignRight="#+id/spinner1"
android:layout_below="#+id/textView1"
android:layout_marginTop="05dp"
android:background="#drawable/btn_calendar"
android:textColor="#FFBF00" />
<AutoCompleteTextView
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignLeft="#+id/button2"
android:layout_alignRight="#+id/spinner1"
android:digits="abcdefghijklmnopwrstuvwxyzABCDEFGHIJKLMNOPWRSTUVWXYZ. "
android:ems="6"
android:hint="Enter Name"
android:inputType="textCapWords"
android:maxLength="25"
android:textColor="#002f44" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText1"
android:layout_below="#+id/editText1"
android:padding="03dp"
android:textColor="#610B0B" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:visibility="invisible" />
<Button
android:id="#+id/button1"
android:layout_width="120dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#drawable/btn_addreminder"
android:text="Save"
android:textColor="#002f44"
android:textStyle="bold"
android:visibility="gone" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="-5dp"
android:background="#drawable/widget_style"
android:orientation="horizontal"
android:visibility="gone" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Self"
android:textColor="#002f44" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:text="Other"
android:textColor="#002f44" />
</RadioGroup>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_alignRight="#+id/Button01"
android:text="Type "
android:textColor="#002f44"
android:textSize="18sp"
android:visibility="gone" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView4"
android:layout_below="#+id/radioGroup1"
android:layout_marginTop="25dp"
android:text="Name"
android:textColor="#002f44"
android:textSize="18sp"
android:visibility="gone" />
<AutoCompleteTextView
android:id="#+id/autoname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:digits="abcdefghijklmnopwrstuvwxyzABCDEFGHIJKLMNOPWRSTUVWXYZ. "
android:ellipsize="end"
android:ems="8"
android:hint="Friends Name"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#002f44"
android:visibility="gone" >
</AutoCompleteTextView>
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner1"
android:layout_alignRight="#+id/spinner1"
android:layout_below="#+id/spinner1"
android:clickable="false"
android:lineSpacingExtra="2.3dp"
android:padding="10dp"
android:text="TextView"
android:textColor="#002f44"
android:textSize="14sp"
android:visibility="invisible" />
<Button
android:id="#+id/Button01"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:layout_marginTop="05dp"
android:background="#drawable/btn_exit"
android:textStyle="bold" />
<Spinner
android:id="#+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView1"
android:layout_alignRight="#+id/editText1"
android:layout_below="#+id/textView2"
android:layout_marginTop="03dp"
android:background="#drawable/drop_down" />
<Button
android:id="#+id/Button02"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="0dp"
android:layout_marginRight="20dp"
android:background="#drawable/btn_addreminder"
android:text="Next"
android:textColor="#002f44"
android:textStyle="bold" />
<Button
android:id="#+id/button4"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignBaseline="#+id/Button02"
android:layout_alignBottom="#+id/Button02"
android:layout_alignParentLeft="true"
android:layout_marginLeft="42dp"
android:background="#drawable/btn_addreminder"
android:text="Skip"
android:textColor="#002f44"
android:textStyle="bold" />
</RelativeLayout>
In the manifest:
android:windowSoftInputMode="stateHidden|adjustResize"
below is the picture:

The problem is that you use alignParentBottom=true for your button. Try to construct the layout without setting this parameter to true.
<Button
android:id="#+id/Button02"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="0dp"
android:layout_marginRight="20dp"
android:background="#drawable/btn_addreminder"
android:text="Next"
android:textColor="#002f44"
android:textStyle="bold" />
EDIT
As the documentation says:
adjustResize The activity's main window is always resized to make room for the soft keyboard on screen.
adjustPan The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.
I suggest you to rethink the design, and use adjustPan instead of adjustResize.
But if your next button is meant to be used to navigate through your edit texts than take a look at this

try to use this android:windowSoftInputMode="stateUnchanged|adjustResize"

Related

handle views of relative layout on screen rotation

My views get messed up on screen rotation. The data I enter in edit-text does not get erased.
How could I handle my views on screen rotation?
without rotation
with rotation
My code:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
tools:context="com.example.juhi_gupta.pizza_corner.Home_Delivery_Activity">
<TextView
android:id="#+id/home_page"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp"
android:text="Home Page"
android:textAllCaps="true"
android:textColor="#32127A"
android:textSize="30sp"
android:textStyle="bold|italic" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/home_page"
android:layout_marginLeft="26dp"
android:layout_marginStart="26dp"
android:layout_marginTop="33dp"
android:text="Name :"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/name"
android:layout_alignBottom="#+id/name"
android:layout_alignEnd="#+id/option_3"
android:layout_alignRight="#+id/option_3"
android:layout_marginTop="33dp"
android:ems="10"
android:hint="enter full name"
android:inputType="textCapWords"
android:textColor="#228B22" />
<TextView
android:id="#+id/items"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/name"
android:layout_alignStart="#+id/name"
android:layout_below="#+id/editText"
android:layout_marginTop="33dp"
android:text="#string/delivery_items"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/items"
android:layout_alignRight="#+id/items"
android:layout_below="#+id/items"
android:layout_marginTop="14dp"
android:text="#string/cheeze_burst"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/option_7"
android:layout_marginLeft="15dp"
android:layout_marginTop="-1dp"
android:layout_toRightOf="#+id/mobile"
android:text="#string/mexican_wave"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/option_2"
android:layout_alignBottom="#+id/option_2"
android:layout_marginStart="12dp"
android:layout_marginLeft="12dp"
android:layout_marginBottom="0dp"
android:layout_toEndOf="#+id/option_2"
android:layout_toRightOf="#+id/option_2"
android:text="#string/extravaganja"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/option_3"
android:layout_alignLeft="#+id/option_1"
android:layout_marginTop="5dp"
android:text="#string/capsicum_twist"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/option_4"
android:layout_alignRight="#+id/editText7"
android:layout_marginTop="2dp"
android:layout_marginRight="-12dp"
android:text="#string/choriza_pizza"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/option_4"
android:layout_marginLeft="24dp"
android:layout_marginTop="-3dp"
android:layout_toRightOf="#+id/mobile"
android:text="#string/golden_corn"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/rate"
android:layout_alignTop="#+id/items"
android:layout_marginLeft="7dp"
android:layout_marginTop="0dp"
android:text="#string/paneer_crisp"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/option_7"
android:layout_marginLeft="14dp"
android:layout_marginTop="-1dp"
android:layout_toRightOf="#+id/Sumit"
android:text="#string/pineapple_pizza"
android:textColor="#32127A"
android:textStyle="bold" />
<TextView
android:id="#+id/quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="2dp"
android:layout_toLeftOf="#+id/home_page"
android:text="#string/quantity"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/quantity"
android:layout_alignBottom="#+id/quantity"
android:layout_alignLeft="#+id/editText"
android:layout_alignStart="#+id/editText"
android:layout_marginLeft="14dp"
android:layout_marginStart="14dp"
android:layout_marginTop="33dp"
android:ems="5"
android:hint="#string/_1_to_1000"
android:inputType="number"
android:textColor="#228B22" />
<TextView
android:id="#+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/quantity"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="2dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="20dp"
android:layout_toStartOf="#+id/home_page"
android:layout_toLeftOf="#+id/home_page"
android:text="#string/address"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/address"
android:layout_marginLeft="23dp"
android:layout_marginTop="-10dp"
android:layout_toRightOf="#+id/option_1"
android:ems="10"
android:hint="#string/enter_full_address"
android:textColor="#228B22" />
<TextView
android:id="#+id/mobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/date"
android:layout_alignBottom="#+id/editText4"
android:layout_marginBottom="12dp"
android:text="#string/mobile_number"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/editText3"
android:layout_alignParentBottom="true"
android:layout_marginTop="10dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="171dp"
android:ems="10"
android:hint="#string/_10_digit_mobile_number"
android:inputType="number"
android:textColor="#228B22" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/name"
android:layout_alignTop="#+id/editText4"
android:layout_marginLeft="2dp"
android:layout_marginTop="54dp"
android:text="#string/delivery_date"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/editText4"
android:layout_alignLeft="#+id/editText4"
android:layout_alignBottom="#+id/date"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="33dp"
android:layout_marginBottom="-18dp"
android:ems="2"
android:hint="#string/dd"
android:inputType="date"
android:textColor="#228B22" />
<EditText
android:id="#+id/editText7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText6"
android:layout_alignBottom="#+id/editText6"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginBottom="-43dp"
android:layout_toEndOf="#+id/editText2"
android:layout_toRightOf="#+id/editText2"
android:ems="4"
android:hint="#string/yyyy"
android:inputType="date"
android:textColor="#228B22" />
<EditText
android:id="#+id/editText6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText5"
android:layout_alignBottom="#+id/editText5"
android:layout_marginEnd="-2dp"
android:layout_marginRight="-2dp"
android:layout_marginBottom="-40dp"
android:layout_toStartOf="#+id/rate"
android:layout_toLeftOf="#+id/rate"
android:ems="2"
android:hint="#string/mm"
android:inputType="date"
android:textColor="#228B22" />
<TextView
android:id="#+id/emailTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/emailText"
android:layout_alignLeft="#+id/quantity"
android:layout_marginLeft="0dp"
android:text="#string/email_id"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold" />
<EditText
android:id="#+id/emailText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText5"
android:layout_alignRight="#+id/option_5"
android:layout_marginTop="20dp"
android:layout_marginRight="24dp"
android:ems="10"
android:hint="#string/abc_gmail_com"
android:textColor="#228B22" />
<Button
android:id="#+id/Sumit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/Cancel"
android:layout_alignBottom="#+id/Cancel"
android:layout_marginTop="33dp"
android:layout_toLeftOf="#+id/option_2"
android:layout_toStartOf="#+id/option_2"
android:background="#ffff00"
android:onClick="open"
android:text="#string/sumit"
android:textStyle="bold" />
<Button
android:id="#+id/Cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/option_6"
android:layout_alignParentBottom="true"
android:layout_marginRight="19dp"
android:layout_marginBottom="12dp"
android:background="#ffff00"
android:onClick="reset_all_input_parameters"
android:text="#string/cancel"
android:textStyle="bold" />
<Button
android:id="#+id/rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/Cancel"
android:layout_alignBottom="#+id/Cancel"
android:layout_marginStart="6dp"
android:layout_marginLeft="6dp"
android:layout_marginTop="33dp"
android:layout_marginBottom="1dp"
android:layout_toEndOf="#+id/option_2"
android:layout_toRightOf="#+id/option_2"
android:background="#ffff00"
android:onClick="rate_page"
android:text="#string/rate_us"
android:textSize="14sp"
android:textStyle="bold" />
</RelativeLayout>
I don't want to fix the orientation of my app. i.e.:-
setRequestedOrientation ( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ) ; or
android:configChanges= " keyboard|keyboardHidden|orientation"
Only use two layouts for each screen orientation in case you really need a different layout for both cases. I suppose that in your case is much better to have one layout that adjust to both cases.
When working with layout, consider using ConstraintLayout because it adjusts for all screen sizes and cases. Trust me, when I was using RelativeLayout and I was laze to learn about ConstraintLayout, I was being dumb because with ConstraintLayout you will gain a lot of time. Imagine coding one layout that will adjust to more than 20 screens.
For your case, you can use this code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff">
<TextView
android:id="#+id/home_page"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="17dp"
android:text="#string/home_page"
android:textAllCaps="true"
android:textColor="#32127A"
android:textSize="30sp"
android:textStyle="bold|italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="Name :"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/home_page" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:ems="10"
android:hint="enter full name"
android:inputType="textCapWords"
android:textColor="#228B22"
app:layout_constraintStart_toEndOf="#+id/name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/name"
app:layout_constraintBottom_toBottomOf="#+id/name"
app:layout_constraintHorizontal_bias="0.0"/>
<TextView
android:id="#+id/items"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="#string/delivery_items"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="#+id/name"
app:layout_constraintTop_toBottomOf="#+id/name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"/>
<LinearLayout
android:id="#+id/radioGroupLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal"
android:weightSum="2"
app:layout_constraintStart_toStartOf="#+id/items"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/items"
app:layout_constraintHorizontal_bias="0.0">
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<RadioButton
android:id="#+id/option_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cheeze_burst"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/mexican_wave"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/extravaganja"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/capsicum_twist"
android:textColor="#32127A"
android:textStyle="bold" />
</RadioGroup>
<RadioGroup
android:id="#+id/radioGroup2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<RadioButton
android:id="#+id/option_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/choriza_pizza"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/golden_corn"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/paneer_crisp"
android:textColor="#32127A"
android:textStyle="bold" />
<RadioButton
android:id="#+id/option_8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/pineapple_pizza"
android:textColor="#32127A"
android:textStyle="bold" />
</RadioGroup>
</LinearLayout>
<TextView
android:id="#+id/quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginTop="40dp"
android:layout_marginStart="20dp"
android:text="#string/quantity"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="#+id/radioGroupLinearLayout"
app:layout_constraintStart_toStartOf="parent"/>
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:ems="5"
android:hint="#string/_1_to_1000"
android:inputType="number"
android:textColor="#228B22"
app:layout_constraintStart_toEndOf="#+id/quantity"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/quantity"
app:layout_constraintBottom_toBottomOf="#+id/quantity"
app:layout_constraintHorizontal_bias="0.0"/>
<TextView
android:id="#+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/quantity"
android:layout_marginTop="20dp"
android:text="#string/address"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="#+id/quantity"
app:layout_constraintStart_toStartOf="#+id/quantity" />
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:ems="10"
android:hint="#string/enter_full_address"
android:textColor="#228B22"
app:layout_constraintStart_toEndOf="#+id/address"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/address"
app:layout_constraintBottom_toBottomOf="#+id/address"
app:layout_constraintHorizontal_bias="0.0"/>
<TextView
android:id="#+id/mobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="#string/mobile_number"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="#+id/address"
app:layout_constraintStart_toStartOf="#+id/address"/>
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:ems="10"
android:hint="#string/_10_digit_mobile_number"
android:inputType="number"
android:textColor="#228B22"
app:layout_constraintStart_toEndOf="#+id/mobile"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/mobile"
app:layout_constraintBottom_toBottomOf="#+id/mobile"
app:layout_constraintHorizontal_bias="0.0"/>
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="#string/delivery_date"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="#+id/mobile"
app:layout_constraintStart_toStartOf="#+id/mobile"/>
<LinearLayout
android:id="#+id/dateLinearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:orientation="horizontal"
app:layout_constraintStart_toEndOf="#+id/date"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/date"
app:layout_constraintBottom_toBottomOf="#+id/date"
app:layout_constraintHorizontal_bias="0.0">
<EditText
android:id="#+id/editText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="2"
android:hint="#string/dd"
android:inputType="date"
android:textColor="#228B22" />
<EditText
android:id="#+id/editText7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="4"
android:hint="#string/yyyy"
android:inputType="date"
android:textColor="#228B22" />
<EditText
android:id="#+id/editText6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="2"
android:hint="#string/mm"
android:inputType="date"
android:textColor="#228B22" />
</LinearLayout>
<TextView
android:id="#+id/emailTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="#string/email_id"
android:textColor="#0000FF"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintTop_toBottomOf="#+id/date"
app:layout_constraintStart_toStartOf="#+id/date"/>
<EditText
android:id="#+id/emailText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:ems="10"
android:hint="#string/abc_gmail_com"
android:textColor="#228B22"
app:layout_constraintStart_toEndOf="#+id/emailTextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/emailTextView"
app:layout_constraintBottom_toBottomOf="#+id/emailTextView"
app:layout_constraintHorizontal_bias="0.0"/>
<Button
android:id="#+id/Sumit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:background="#ffff00"
android:onClick="open"
android:text="#string/sumit"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="#+id/Cancel"
app:layout_constraintTop_toBottomOf="#+id/emailTextView"
app:layout_constraintBottom_toBottomOf="parent"/>
<Button
android:id="#+id/Cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffff00"
android:onClick="reset_all_input_parameters"
android:text="#string/cancel"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/Sumit"
app:layout_constraintTop_toTopOf="#+id/Sumit"
app:layout_constraintBottom_toBottomOf="#+id/Sumit"
app:layout_constraintEnd_toStartOf="#+id/rate"/>
<Button
android:id="#+id/rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffff00"
android:onClick="rate_page"
android:text="#string/rate_us"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/Cancel"
app:layout_constraintTop_toTopOf="#+id/Cancel"
app:layout_constraintBottom_toBottomOf="#+id/Cancel"
app:layout_constraintEnd_toEndOf="parent"/>
</android.support.constraint.ConstraintLayout>
</ScrollView>
You can create another view for the same page in the editor. In the upper settings, choose orientation and create one for horizontal orientation. Set everything as you wish and you app will use the version you created when the orientation changes.
In orientation changes everything is rendered again in Android. However, as far as I know, you should now lose the EditText entries. If your TextViews are also set correctly in vertical mode, after setting up horizontal mode, they should also appear as expected.
A simple way to obtain a landscape layout is creating a layout-land resource directory folder.
Right click on
Res folder >> New >> AndroidResoursceDirectory
A dialogue box appears in that select Resource type as layout from the drop-down and select orientation from qualifiers and add landscape and click ok. Hence a folder will create under the res folder "layout-land".
Copy your current layout and paste in the layout-land folder and then edit your layout as per how you want to display it while orientation changes to the landscape mode.
By this method when you shift your app orientation from portrait to landscape you can create the same view designed for landscape mode.

EditText in popup window: keyboard isn't shown

I've created a layout for a survey as a popup window, but somehow keyboard isn't shown when a focus is true, even after a tap to the edittext...
In other activities, all EditTexts work correctly.
Recently, I've changed app Theme to AppCompat to implement Material components. I am not sure it can impact, but no ideas from my side, why it doesn't work.
Any ideas?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#66ccff"
android:gravity="center" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageSurveyClose"
android:layout_centerHorizontal="true"
android:paddingTop="40dp"
android:fontFamily="sans-serif"
android:gravity="center"
android:text="Question"
android:textColor="#ffffff"
android:textSize="22dp" />
<ImageButton
android:id="#+id/imageSurveyClose"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/close"
android:background="#null" />
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Send" />
<RadioGroup
android:id="#+id/radioGroup2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:paddingTop="20dp"
android:layout_marginLeft="20dp"
>
<RadioButton
android:id="#+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="v1"
android:layout_gravity="left"
android:fontFamily="sans-serif"
android:textSize="22dp"
android:buttonTint="#ffffff"
android:textColor="#ffffff"
android:layout_marginTop="10dp"
/>
<RadioButton
android:id="#+id/radio1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:fontFamily="sans-serif"
android:text="v2"
android:buttonTint="#ffffff"
android:layout_marginTop="12dp"
android:textColor="#ffffff"
android:textSize="22dp" />
<RadioButton
android:id="#+id/radio2"
android:layout_width="wrap_content"
android:buttonTint="#ffffff"
android:layout_height="wrap_content"
android:text="v3"
android:layout_gravity="left"
android:fontFamily="sans-serif"
android:layout_marginTop="12dp"
android:textSize="22dp"
android:textColor="#ffffff"
/>
</RadioGroup>
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/radioGroup2"
android:layout_below="#+id/radioGroup2"
android:layout_marginTop="47dp"
android:ems="10" >
<requestFocus />
</EditText>
</RelativeLayout>
You can try removing the <requestFocus /> element in the EditText and see whether the keyboard appears. Afterwards you can request the focus programmatically inside the activity.

Android RelativeLayout, hiding views and pushing the views beneath up

I have a RelativeLayout which includes a Spinner and some RadioButtons, based on the selection of these I have to hide some views and make others visible. The problem is if I make the views GONE by view.setVisibility(View.GONE) the layout gets messed up, the views overlap, if I use view.Visibility(View.INVISIBLE) everything is fine but the missing views create a void on the page. I want to push the views beneath up to properly augment the page. Below is a better explanation:
So far the code I have is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bg_app" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="60dp"
android:background="#drawable/drop_down" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner1"
android:layout_below="#+id/textView5"
android:layout_marginTop="30dp"
android:text="xxx"
android:textColor="#002f44"
android:textSize="18sp" />
<Button
android:id="#+id/button2"
android:layout_width="170dp"
android:layout_height="30dp"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignRight="#+id/spinner1"
android:background="#drawable/btn_calendar"
android:textColor="#FFBF00" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:visibility="invisible" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="20dp"
android:scaleType="centerCrop" />
<AutoCompleteTextView
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/spinner1"
android:layout_alignTop="#+id/imageView1"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/imageView1"
android:ems="6"
android:hint="xx xx"
android:inputType="textPersonName"
android:maxLength="25"
android:textColor="#002f44" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText1"
android:layout_below="#+id/editText1"
android:padding="03dp"
android:textColor="#610B0B" />
<Button
android:id="#+id/button1"
android:layout_width="120dp"
android:layout_height="50dp"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2"
android:background="#drawable/btn_addreminder"
android:text="xxx"
android:textColor="#002f44"
android:textStyle="bold" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner1"
android:layout_below="#+id/spinner1"
android:layout_marginTop="20dp"
android:text="xxx "
android:textColor="#002f44"
android:textSize="18sp" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/spinner1"
android:layout_alignTop="#+id/textView4"
android:layout_marginTop="-5dp"
android:background="#drawable/widget_style"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="xxx"
android:textColor="#002f44" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:text="xxx"
android:textColor="#002f44" />
</RadioGroup>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner1"
android:layout_below="#+id/radioGroup1"
android:layout_marginTop="25dp"
android:text="xxx"
android:textColor="#002f44"
android:textSize="18sp" />
<AutoCompleteTextView
android:id="#+id/autoname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView5"
android:layout_alignRight="#+id/spinner1"
android:ellipsize="end"
android:ems="8"
android:hint="xx xx"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#002f44" >
</AutoCompleteTextView>
<Button
android:id="#+id/button4"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignLeft="#+id/imageView1"
android:layout_below="#+id/button1"
android:layout_marginLeft="05dp"
android:layout_marginTop="66dp"
android:background="#drawable/btn_addreminder"
android:text="xxx"
android:textColor="#002f44"
android:textStyle="bold" />
<Button
android:id="#+id/Button01"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/btn_addreminder"
android:text="xxx"
android:textColor="#002f44"
android:textStyle="bold" />
<Button
android:id="#+id/Button02"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignBaseline="#+id/button4"
android:layout_alignBottom="#+id/button4"
android:layout_alignRight="#+id/editText1"
android:background="#drawable/btn_addreminder"
android:text="xxx"
android:textColor="#002f44"
android:textStyle="bold" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
You should use alignWithParentIfMissing attribute.
I've reworked your layout, try it
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="60dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:paddingLeft="20dp"
android:paddingRight="20dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView5"
android:layout_marginTop="30dp"
android:text="xxx"
android:textColor="#002f44"
android:textSize="18sp" />
<Button
android:id="#+id/button2"
android:layout_width="170dp"
android:layout_height="30dp"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignParentRight="true"
android:textColor="#FFBF00" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:visibility="invisible" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginTop="20dp"
android:scaleType="centerCrop" />
<AutoCompleteTextView
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imageView1"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#+id/imageView1"
android:ems="6"
android:hint="xx xx"
android:inputType="textPersonName"
android:maxLength="25"
android:textColor="#002f44" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText1"
android:layout_below="#+id/editText1"
android:padding="03dp"
android:textColor="#610B0B" />
<Button
android:id="#+id/button1"
android:layout_width="120dp"
android:layout_height="50dp"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2"
android:text="xxx"
android:textColor="#002f44"
android:textStyle="bold" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:text="xxx "
android:textColor="#002f44"
android:textSize="18sp" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView4"
android:layout_marginTop="-5dp"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="xxx"
android:textColor="#002f44" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:text="xxx"
android:textColor="#002f44" />
</RadioGroup>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/radioGroup1"
android:layout_marginTop="25dp"
android:text="xxx"
android:textColor="#002f44"
android:textSize="18sp" />
<AutoCompleteTextView
android:id="#+id/autoname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView5"
android:layout_alignParentRight="true"
android:ellipsize="end"
android:ems="8"
android:hint="xx xx"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#002f44" >
</AutoCompleteTextView>
<Button
android:id="#+id/button4"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignLeft="#+id/imageView1"
android:layout_below="#+id/button1"
android:layout_marginLeft="05dp"
android:layout_marginTop="66dp"
android:text="xxx"
android:textColor="#002f44"
android:textStyle="bold" />
<Button
android:id="#+id/Button01"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="xxx"
android:textColor="#002f44"
android:textStyle="bold" />
<Button
android:id="#+id/Button02"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignBaseline="#+id/button4"
android:layout_alignBottom="#+id/button4"
android:layout_alignRight="#+id/editText1"
android:text="xxx"
android:textColor="#002f44"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Use LinearLayout(vertical) inside ScrollView and create RelativeLayouts as child of this LinearLayout. Set height of these RelativeLayout as wrap content, so that as you set visibility of items as GONE its height will shrink.
Now as per image that you have given here, you can have spinner first then below that a relative layout which will contain two (horizontal) items that you wanna hide. then next two (horizontal) items in another layout and then your image, editText and Button in third layout.
So you hide any relative layout others will arrange properly.
I would recommend to create a view of height 1dp with transparent background below texView4 and then set android:layout_below="#id/view" attribute for textView5. Here is how the changes to the layout would look like:
</RadioGroup> <!-- RadioGroup ends -->
<View
android:id="#+id/view"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#id/textView4"
android:background="#color/transparent"/>
<!-- Changed layout_below attribute value -->
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner1"
android:layout_below="#id/view"
android:layout_marginTop="25dp"
android:text="xxx"
android:textColor="#002f44"
android:textSize="18sp" />
And here is how the layout looks like with textView4 and RadioGroup gone:

android softkeyboard pushes layout up

So basically i have a main layout which is a log in screen. The problem is that whole Relative-layout goes off the screen when i tap onto Edittext field...
Here is my xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background_gradient"
android:theme="#android:style/Theme.NoTitleBar"
tools:context=".MainActivity" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="60dp"
android:baselineAlignBottom="true"
android:contentDescription="#string/skedo"
android:src="#drawable/logo" />
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_above="#+id/editText2"
android:layout_centerHorizontal="true"
android:layout_marginLeft="13dp"
android:layout_marginRight="13dp"
android:drawableLeft="#drawable/user"
android:drawablePadding="13dp"
android:paddingLeft="13dp"
android:inputType="textEmailAddress"
android:background="#drawable/round_corners"
android:ems="10"
android:hint="#string/email" />
<EditText
android:id="#+id/editText2"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:layout_marginLeft="13dp"
android:layout_marginRight="13dp"
android:layout_marginTop="8dp"
android:drawableLeft="#drawable/lock"
android:drawablePadding="13dp"
android:paddingLeft="13dp"
android:background="#drawable/round_corners"
android:ems="10"
android:hint="#string/password"
android:inputType="textPassword" >
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText2"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:textSize="17sp"
android:shadowColor="#000000"
android:shadowRadius="1"
android:shadowDx="0"
android:shadowDy="1"
android:text="#string/login"
android:textColor="#ffffff"
android:background="#drawable/button_states" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/button1"
android:layout_centerInParent="true"
android:layout_marginTop="23dp"
android:clickable="true"
android:text="#string/forgot_password"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="13sp" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:contentDescription="#string/imgdesc"
android:src="#drawable/or" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView2"
android:shadowColor="#ffffff"
android:shadowRadius="1"
android:shadowDx="0"
android:textSize="14sp"
android:textStyle="bold"
android:shadowDy="1"
android:layout_centerHorizontal="true"
android:layout_marginTop="23dp"
android:text="#string/register"
android:background="#drawable/create_account"
/>
So when this happens my logo disappears off the screen and i would like it to be showing. The best example would be facebook log in screen, where when you tap on editText it squashes everything and logo is still visible. So how can i achieve such effect?
So when nothing is pressed:
http://postimage.org/image/swdtggnil/
When keyboard appears
http://postimage.org/image/5pbdfrftl/
I want it to behave exactly like that.
If I have not misunderstood you can add
android:windowSoftInputMode="adjustPan"
in the AndroidManifest.xml
<activity
android:name="yourActivity"
android:windowSoftInputMode="adjustPan" >
</activity>

How to resize my xml so that it will fit nicely on the emulator

I am currently having trouble with my GUI design because of the whole page will be shifted to the right and become like this:
create_events.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/crimson"
android:orientation="vertical" >
<TextView
android:id="#+id/txtDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/txtDate"
android:layout_below="#+id/txtDate"
android:layout_marginTop="16dp"
android:text="Title:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#android:id/text1"
android:layout_alignBottom="#android:id/text1"
android:layout_marginLeft="34dp"
android:layout_toRightOf="#android:id/text1" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#android:id/text1"
android:layout_below="#+id/spinner1"
android:layout_marginTop="18dp"
android:text="Location:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner1"
android:layout_alignTop="#+id/textView2"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/editText1"
android:layout_marginTop="15dp"
android:text="Start At:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_toRightOf="#+id/textView2"
android:ems="10"
android:inputType="time" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/editText2"
android:layout_marginTop="22dp"
android:text="End At:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView3"
android:layout_toRightOf="#+id/textView2"
android:ems="10"
android:inputType="time" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_below="#+id/editText3"
android:layout_marginTop="23dp"
android:text="Alarm:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/btnAlarm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView4"
android:layout_alignBottom="#+id/textView4"
android:layout_alignLeft="#+id/editText3"
android:text="Set Alarm" />
<Button
android:id="#+id/btnMain"
style="#style/main_menu"
android:layout_width="170dp"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="14dp"
android:layout_toRightOf="#+id/textView1"
android:background="#drawable/blue_load_picbutton"
android:text="Main Menu" />
<Button
android:id="#+id/btnEvent"
style="#style/main_menu"
android:layout_width="170dp"
android:layout_height="60dp"
android:layout_above="#+id/btnMain"
android:layout_alignLeft="#+id/btnMain"
android:layout_marginBottom="14dp"
android:background="#drawable/blue_load_picbutton"
android:text="Create Event" />
<TextView
android:id="#+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/editText1"
android:text="TextView" />
</RelativeLayout>
I do not know the reason as to why the whole screen is shifted. The last time I opened, it was fits in the screen perfectly. Anyone has any idea why, can you please help me? Thanks.
Edited:
After doing according to what #Andy Res said, My screen currently is displayed like this. For your reference, the skin that I am using for my emulator is WVGA854.
I see you allign your Title to the right of txtDate.
And then all the controls are aligned having the Title as a reference.
So I believe this line may cause the shifting to the right.
<TextView
android:id="#android:id/text1"
android:layout_alignRight="#+id/txtDate"
.... />
Try to remove: android:layout_alignRight="#+id/txtDate" and see if any effect.

Categories

Resources