I have a button inside relative layout that I want to center along with input edit text. I added android:gravity="center" to relative layout, every was centered correctly other than the button, I even tried to add android:layout_centerInParent="true" to the button but it didn't work. What could be the issue?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_gravity="bottom">
<ImageView
android:id="#+id/imageView"
android:src="#drawable/logo"
android:layout_weight=".3"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"/>
<RelativeLayout
android:layout_weight=".1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<EditText
android:id="#+id/et_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:inputType="textEmailAddress"
android:ems="10"
android:hint="Email"/>
<EditText
android:id="#+id/et_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/et_email"
android:inputType="textPassword"
android:hint="Password"
android:ems="10"
android:layout_marginBottom="20dp"
android:imeOptions="actionDone"/>
<Button
android:id="#+id/b_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/et_password"
android:text="Login"/>
</RelativeLayout>
<View
android:layout_weight=".1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
Button is not centered:
android:gravity="center" is a property of LinearLayout so its direct child (the RelativeLayout) inside of it. You still need to center the children inside the RelativeLayout. To center the Button inside of its parent RelativeLayout use android:layout_centerHorizontal="true"
<Button
android:id="#+id/b_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/et_password"
android:text="Login"
android:layout_centerHorizontal="true"/> // here
Docs
Update
Center each View inside of the RelativeLayout
<RelativeLayout
android:layout_weight=".1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<EditText
android:id="#+id/et_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:inputType="textEmailAddress"
android:ems="10"
android:hint="Email"
android:layout_centerHorizontal="true"/>
<EditText
android:id="#+id/et_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/et_email"
android:inputType="textPassword"
android:hint="Password"
android:ems="10"
android:layout_marginBottom="20dp"
android:imeOptions="actionDone"
android:layout_centerHorizontal="true"/>
<Button
android:id="#+id/b_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/et_password"
android:text="Login"
android:layout_centerHorizontal="true"/>
Try this code:
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_gravity="bottom">
<ImageView
android:id="#+id/imageView"
android:src="#drawable/logo"
android:layout_weight=".3"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"/>
<RelativeLayout
android:layout_weight=".1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<EditText
android:id="#+id/et_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:inputType="textEmailAddress"
android:ems="10"
android:hint="Email"/>
<EditText
android:id="#+id/et_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/et_email"
android:inputType="textPassword"
android:hint="Password"
android:ems="10"
android:layout_marginBottom="20dp"
android:imeOptions="actionDone"/>
<Button
android:id="#+id/b_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/et_password"
android:layout_gravity="center"
android:text="Login"/>
</RelativeLayout>
<View
android:layout_weight=".1"
android:layout_width="match_parent"
android:layout_height="0dp"/>
Try this.. Use LinearLayout instead of RelativeLayout
<LinearLayout
android:layout_weight=".1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<EditText
android:id="#+id/et_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:inputType="textEmailAddress"
android:ems="10"
android:hint="Email"/>
<EditText
android:id="#+id/et_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/et_email"
android:inputType="textPassword"
android:hint="Password"
android:ems="10"
android:layout_marginBottom="20dp"
android:imeOptions="actionDone"/>
<Button
android:id="#+id/b_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/et_password"
android:text="Login" />
</LinearLayout>
OR in Your same layout just remove android:gravity="center" add android:layout_centerHorizontal="true" for each EditText and Button
<RelativeLayout
android:layout_weight=".1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/et_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:inputType="textEmailAddress"
android:layout_centerHorizontal="true"
android:ems="10"
android:hint="Email"/>
<EditText
android:id="#+id/et_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/et_email"
android:inputType="textPassword"
android:hint="Password"
android:layout_centerHorizontal="true"
android:ems="10"
android:layout_marginBottom="20dp"
android:imeOptions="actionDone"/>
<Button
android:id="#+id/b_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/et_password"
android:layout_centerHorizontal="true"
android:text="Login" />
</RelativeLayout>
Related
I have a problem with height of linear layout. When I use only linear layout, my form is scaled to screen size, and everything look like good. But now, I need to have scrollview only when I click an edittext and keyboard appear. I set scrollview as a root of my layout, but it extended height of this layout. Scrollview should be work only while keyboard appear, but now it work's every time and ruined my linearlayout. So right now, when I'm using a scrollview, layout is bigger than screen size. What should I do?
<ScrollView
android:layout_width="match_parent"
android:id="#+id/scrollView"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" android:layout_height="match_parent"
tools:context=".activities.FormDialog"
>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
android:layout_alignParentTop="true" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" android:background="#drawable/new_background">
<ImageView
android:layout_width="84dp"
android:id="#+id/imageView"
android:src="#drawable/applogo"
android:layout_alignParentTop="true" android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:layout_gravity="end" android:layout_marginRight="20dp"
android:layout_height="29dp"/>
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" android:layout_alignParentStart="true"
>
<TextView
android:text="Info"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/missedCall"
android:layout_alignParentTop="true" android:layout_centerHorizontal="true"
android:textColor="#color/apptheme_color"
android:layout_marginBottom="16dp" android:textSize="15sp" android:layout_marginTop="16dp"/>
</RelativeLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_weight="2" android:layout_height="wrap_content" android:layout_width="match_parent"
android:layout_marginLeft="25dp" android:layout_marginRight="25dp"
android:layout_marginBottom="6dp" android:weightSum="1">
<ImageView
android:text="Button"
android:id="#+id/leftButton"
android:layout_width="40dp" android:layout_height="40dp"
android:layout_gravity="center_vertical" android:src="#drawable/left"/>
<TextView
android:text="Text"
android:layout_width="244dp"
android:layout_height="match_parent" android:id="#+id/numberTextView"
android:gravity="center_vertical|center_horizontal|center"
android:textColor="#color/apptheme_color" android:textSize="24sp"
android:layout_weight="1"/>
<ImageView
android:text="Button"
android:id="#+id/rightButton"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_width="40dp" android:layout_height="40dp"
android:src="#drawable/right_arrow"/>
</LinearLayout>
<TextView
android:text="Text"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="#+id/textView7"
android:textColor="#color/apptheme_color" android:textAlignment="viewStart"
android:textSize="18sp"
android:layout_weight="0.5"
android:layout_below="#+id/missedCall" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" android:layout_marginLeft="30dp"
android:layout_marginRight="25dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/nameTextView"
android:background="#drawable/blueborder"
android:textColorHint="#FFFFFF"
android:textColor="#FFFFFF"
android:layout_marginLeft="25dp" android:layout_marginRight="25dp" android:layout_marginTop="16dp"
android:paddingTop="10dp" android:paddingBottom="10dp"
android:hint="Edit1" android:paddingLeft="10dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/detailsTextView"
android:background="#drawable/blueborder"
android:textColorHint="#FFFFFF"
android:textColor="#FFFFFF"
android:layout_marginLeft="25dp" android:layout_marginRight="25dp" android:layout_marginTop="6dp"
android:paddingTop="10dp" android:paddingBottom="10dp" android:paddingLeft="10dp"
android:layout_weight="1"
android:hint="Edit2"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textWebEmailAddress"
android:ems="10"
android:id="#+id/emailEditText"
android:textColorHint="#FFFFFF"
android:textColor="#FFFFFF"
android:layout_marginLeft="25dp" android:layout_marginRight="25dp" android:layout_marginTop="6dp"
android:paddingTop="10dp" android:paddingBottom="10dp" android:paddingLeft="10dp"
android:layout_weight="1"
android:hint="Edit3"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/companyEditText"
android:background="#drawable/blueborder"
android:textColorHint="#FFFFFF"
android:textColor="#FFFFFF"
android:layout_marginLeft="25dp" android:layout_marginRight="25dp" android:layout_marginTop="6dp"
android:paddingTop="10dp" android:paddingBottom="10dp" android:paddingLeft="10dp"
android:layout_weight="1"
android:hint="Edit4"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine|textPersonName"
android:ems="10"
android:id="#+id/noteEditText"
android:background="#drawable/blueborder"
android:textColorHint="#FFFFFF"
android:layout_marginLeft="25dp" android:layout_marginRight="25dp" android:layout_marginTop="6dp"
android:paddingTop="10dp" android:paddingBottom="20dp" android:paddingLeft="10dp"
android:layout_weight="3.33"
android:scrollbars="vertical" android:hint="Edit5" android:lines="2" android:textColor="#FFFFFF"
android:gravity="top|center_vertical"/>
<CheckBox
android:text="Check1"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="#+id/newContactCheckbox"
android:layout_marginLeft="20dp"
android:textColor="#color/apptheme_color"
android:layout_weight="1"
/>
<CheckBox
android:text="Check2"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="#+id/isWantedCheckbox" android:layout_marginLeft="20dp"
android:textColor="#color/apptheme_color"
android:layout_weight="1"
/>
<Button
android:text="Send"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="#+id/addButton" android:layout_weight="2"
android:textColor="#02485a" android:background="#drawable/blackborder"
android:layout_marginLeft="25dp" android:layout_marginRight="25dp"
android:layout_marginBottom="16dp"/>
<TextView
android:text="Cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/notRegisterTextView"
android:textSize="14sp" android:textColor="#color/apptheme_color"
android:layout_marginLeft="25dp" android:padding="7dp"
/>
</LinearLayout>
</ScrollView>
And in Manifest I set android:windowSoftInputMode="stateUnchanged|adjustResize"
I'm looking for an answer what should I do to prepare static layout ( without ScrollView, because when I put as a root ScrollView, then my LinearLayout is bigger than screen size, without scrollview, linearlayout is perfect ), so I have a form with 5 edittexts, and when I click on once of them, keyboard appear and now I need scroll on this form. I tried use ScrollView, android:windowSoftInputMode="adjustPan" and much more, but nothing works.
<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="#aa000000">
<ScrollView
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent">
<RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/background"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignWithParentIfMissing="false" android:scaleType="centerCrop"
android:id="#+id/blueBackground"
android:background="#aa000000"
/>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
android:layout_alignParentTop="true" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<ImageView
android:layout_width="match_parent"
android:id="#+id/imageView"
android:src="#drawable/applogo"
android:layout_alignParentTop="true" android:layout_centerHorizontal="true"
android:layout_height="60dp" android:layout_marginTop="25dp"
android:layout_weight="2"
/>
<TextView
android:text="Text1"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="#+id/textView7"
android:textColor="#color/apptheme_color" android:textAlignment="viewStart"
android:gravity="center_horizontal" android:layout_marginTop="35dp" android:textSize="18sp"
android:layout_weight="1"
/>
<TextView
android:text="Text2"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="#+id/numberTextView" android:gravity="center_horizontal"
android:textColor="#color/apptheme_color" android:textSize="24sp"
android:layout_weight="1"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/edit1"
android:background="#drawable/blueborder"
android:textColorHint="#FFFFFF"
android:textColor="#FFFFFF"
android:layout_marginLeft="25dp" android:layout_marginRight="25dp" android:layout_marginTop="16dp"
android:paddingTop="10dp" android:paddingBottom="10dp" android:paddingLeft="10dp"
android:layout_weight="1"
android:hint="Edit1"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/edit2"
android:background="#drawable/blueborder"
android:textColorHint="#FFFFFF"
android:textColor="#FFFFFF"
android:layout_marginLeft="25dp" android:layout_marginRight="25dp" android:layout_marginTop="6dp"
android:paddingTop="10dp" android:paddingBottom="10dp" android:paddingLeft="10dp"
android:layout_weight="1"
android:hint="Edit2"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/edi3"
android:background="#drawable/blueborder"
android:textColorHint="#FFFFFF"
android:textColor="#FFFFFF"
android:layout_marginLeft="25dp" android:layout_marginRight="25dp" android:layout_marginTop="6dp"
android:paddingTop="10dp" android:paddingBottom="10dp" android:paddingLeft="10dp"
android:layout_weight="1"
android:hint="Edit3"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/edit4"
android:background="#drawable/blueborder"
android:textColorHint="#FFFFFF"
android:textColor="#FFFFFF"
android:layout_marginLeft="25dp" android:layout_marginRight="25dp" android:layout_marginTop="6dp"
android:paddingTop="10dp" android:paddingBottom="10dp" android:paddingLeft="10dp"
android:layout_weight="1"
android:hint="Edit4"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine|textPersonName"
android:ems="10"
android:id="#+id/edit5"
android:background="#drawable/blueborder"
android:textColorHint="#FFFFFF"
android:layout_marginLeft="25dp" android:layout_marginRight="25dp" android:layout_marginTop="6dp"
android:paddingTop="10dp" android:paddingBottom="20dp" android:paddingLeft="10dp"
android:layout_weight="3.33"
android:scrollbars="vertical" android:hint="Notatka" android:lines="2" android:textColor="#FFFFFF"/>
<CheckBox
android:text="Checkbox1"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="#+id/check1" android:layout_marginLeft="20dp"
android:textColor="#color/apptheme_color"
android:layout_weight="1"
/>
<CheckBox
android:text="Checkbox2"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="#+id/check2" android:layout_marginLeft="20dp"
android:textColor="#color/apptheme_color"
android:layout_weight="1"
/>
<Button
android:text="Save"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="#+id/button" android:layout_weight="2"
android:textColor="#02485a" android:background="#drawable/blackborder"
android:layout_marginLeft="25dp" android:layout_marginRight="25dp"
android:layout_marginBottom="16dp"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
Add ScrollView inside RelativeLayout with fillViewport property
<ScrollView
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent">
</ScrollView>
I have a register layout. In this if I click on first edit text the keyboard appears and other views gets hidden under the keyboard. So I want to make the layout scrollable so we can scroll up and use the next edit text while the keyboard is popped up.
I tried to add the scroll view for this in layout. Also set this android:windowSoftInputMode="adjustResize" in manifest for the activity. But it makes all the views shift up , so all the layouts got merged with each other.
Following is the image what I got.
EDIT: Edited layout : Edited again.Still it works same.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/my_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout android:id="#+id/login" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="200dp"
android:layout_height="100dp"
android:id="#+id/imageView2"
android:src="#drawable/logo_1"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerInParent="true"
android:id="#+id/linearLayout5">
<LinearLayout android:layout_width="250dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:id="#+id/linearLayoutSecondName"
android:background="#drawable/field_1"
android:layout_below="#+id/imageView2"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:id="#+id/imageView3"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dp"
android:background="#drawable/user" />
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="40dp" android:hint="#string/user_id"
android:maxLines="1"
android:singleLine="true"
android:inputType="text"
android:layout_below="#+id/linearLayoutFirstName"
android:layout_toRightOf="#+id/linearLayoutFirstName"
android:layout_toEndOf="#+id/linearLayoutFirstName"
android:background="#android:color/transparent"
android:layout_marginLeft="20dp"
android:layout_gravity="center"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout android:layout_width="250dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:id="#+id/linearLayoutFirstName"
android:layout_centerVertical="true"
android:layout_alignStart="#+id/linearLayoutSecondName"
android:layout_below="#+id/linearLayoutSecondName"
android:layout_marginTop="20dp"
android:background="#drawable/field_1">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:id="#+id/imageView4"
android:layout_marginLeft="15dp"
android:background="#drawable/email"
android:layout_gravity="center" />
<EditText android:id="#+id/password" android:layout_width="match_parent"
android:layout_height="40dp" android:hint="EMAIL "
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:maxLines="1" android:singleLine="true"
android:layout_gravity="center"
android:layout_below="#+id/linearLayoutSecondName"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"
android:background="#android:color/transparent"
android:textSize="12sp"
android:inputType="textEmailAddress" />
</LinearLayout>
<LinearLayout
android:layout_width="250dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:id="#+id/linearLayout4"
android:background="#drawable/field_1"
android:layout_below="#+id/linearLayout5"
android:layout_alignRight="#+id/imageView2"
android:layout_alignEnd="#+id/imageView2"
android:layout_marginTop="20dp">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:id="#+id/imageView5"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dp"
android:background="#drawable/pass" />
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:hint="#string/prompt_password"
android:maxLines="1"
android:singleLine="true"
android:inputType="textPassword|text"
android:layout_below="#+id/linearLayoutFirstName"
android:layout_toRightOf="#+id/linearLayoutFirstName"
android:layout_toEndOf="#+id/linearLayoutFirstName"
android:background="#android:color/transparent"
android:layout_marginLeft="20dp"
android:layout_gravity="center"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="250dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:id="#+id/linearLayout6"
android:background="#drawable/field_1"
android:layout_below="#+id/linearLayout5"
android:layout_alignLeft="#+id/linearLayout5"
android:layout_alignStart="#+id/linearLayout5"
android:layout_marginTop="20dp">
<ImageView
android:layout_width="15dp"
android:layout_height="25dp"
android:id="#+id/imageView6"
android:layout_gravity="center_vertical"
android:layout_marginLeft="15dp"
android:background="#drawable/phone" />
<EditText
android:layout_width="30dp"
android:layout_height="match_parent"
android:inputType="number"
android:ems="10"
android:id="#+id/editText"
android:layout_marginLeft="20dp"
android:background="#android:color/transparent"
android:hint="+91"
android:textSize="14sp" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background = "#android:color/darker_gray"
android:layout_marginTop="05dp"
android:layout_marginBottom="05dp">
</View>
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:hint="MOBILE NO"
android:maxLines="1"
android:singleLine="true"
android:layout_below="#+id/linearLayoutFirstName"
android:layout_toRightOf="#+id/linearLayoutFirstName"
android:layout_toEndOf="#+id/linearLayoutFirstName"
android:background="#android:color/transparent"
android:layout_gravity="center"
android:textSize="12sp"
android:layout_marginLeft="05dp"
android:inputType="number" />
</LinearLayout>
</LinearLayout>
<Button android:id="#+id/sign_up_button"
android:layout_width="match_parent" android:layout_height="40dp"
android:text="SIGN UP"
android:textSize="14sp"
android:textColor="#android:color/white"
style="?android:attr/borderlessButtonStyle"
android:layout_gravity="left"
android:background="#drawable/rounded_shape"
android:layout_alignParentBottom="false"
android:layout_alignRight="#+id/linearLayout5"
android:layout_alignEnd="#+id/linearLayout5"
android:layout_alignLeft="#+id/linearLayout5"
android:layout_alignStart="#+id/linearLayout5"
android:layout_below="#+id/linearLayout5"
android:layout_marginTop="40dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="#string/register"
android:id="#+id/alreadyRegistered"
android:focusable="false"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:textColorLink="#android:color/darker_gray"
android:textIsSelectable="true"
android:textSize="14sp"
android:layout_marginBottom="10dp"
android:textAlignment="center" />
</RelativeLayout>
</ScrollView>
How to do this?
Doing same with another layout, but in this when I click on first edit text , the first edit text also scrolls up while the keyboard is popped up. What's wrong here? Used this too.
android:windowSoftInputMode="stateHidden|adjustResize"
fragment :
<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">
<ScrollView
android:id="#+id/my_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/linearLayout5"
android:layout_gravity="center"
android:layout_centerHorizontal="true">
<LinearLayout android:layout_width="300dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:id="#+id/linearLayoutFirstName"
android:layout_below="#+id/linearLayoutSecondName"
android:background="#drawable/field_1"
android:layout_marginTop="20dp">
<EditText android:id="#+id/password" android:layout_width="match_parent"
android:layout_height="40dp" android:hint="First Name"
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:maxLines="1" android:singleLine="true"
android:layout_gravity="center"
android:layout_below="#+id/linearLayoutSecondName"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"
android:background="#android:color/transparent"
android:textSize="12sp"
android:inputType="text" />
</LinearLayout>
<LinearLayout
android:layout_width="300dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:id="#+id/linearLayoutSecondName"
android:background="#drawable/field_1"
android:layout_below="#+id/linearLayout5"
android:layout_alignRight="#+id/imageView2"
android:layout_alignEnd="#+id/imageView2"
android:layout_marginTop="20dp">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:hint="Last Name"
android:maxLines="1"
android:singleLine="true"
android:inputType="text"
android:layout_below="#+id/linearLayoutFirstName"
android:layout_toRightOf="#+id/linearLayoutFirstName"
android:layout_toEndOf="#+id/linearLayoutFirstName"
android:background="#android:color/transparent"
android:layout_marginLeft="20dp"
android:layout_gravity="center"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="300dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:id="#+id/linearLayoutDOB"
android:background="#drawable/field_1"
android:layout_below="#+id/linearLayout5"
android:layout_alignLeft="#+id/linearLayout5"
android:layout_alignStart="#+id/linearLayout5"
android:layout_marginTop="20dp">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:hint="Date Of Birth"
android:singleLine="true"
android:layout_below="#+id/linearLayoutFirstName"
android:layout_toRightOf="#+id/linearLayoutFirstName"
android:layout_toEndOf="#+id/linearLayoutFirstName"
android:background="#android:color/transparent"
android:layout_gravity="center"
android:textSize="12sp"
android:layout_marginLeft="20dp"
android:inputType="date" />
</LinearLayout>
<LinearLayout
android:layout_width="300dp"
android:layout_height="40dp"
android:id="#+id/linearLayoutLocation"
android:layout_below="#+id/linearLayoutSecondName"
android:background="#drawable/field_1"
android:layout_marginTop="20dp"
android:layout_gravity="center">
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="40dp"
android:hint="Location"
android:maxLines="1"
android:singleLine="true"
android:layout_gravity="center"
android:layout_below="#+id/linearLayoutSecondName"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"
android:background="#android:color/transparent"
android:textSize="12sp"
android:inputType="text" />
</LinearLayout>
<LinearLayout
android:layout_width="300dp"
android:layout_height="40dp"
android:id="#+id/linearLayoutAnniversary"
android:layout_below="#+id/linearLayoutSecondName"
android:background="#drawable/field_1"
android:layout_marginTop="20dp"
android:layout_gravity="center">
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="40dp"
android:hint="Anniversary"
android:maxLines="1"
android:singleLine="true"
android:layout_gravity="center"
android:layout_below="#+id/linearLayoutSecondName"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"
android:background="#android:color/transparent"
android:textSize="12sp"
android:inputType="date" />
</LinearLayout>
<LinearLayout
android:layout_width="300dp"
android:layout_height="40dp"
android:id="#+id/linearLayout8"
android:layout_below="#+id/linearLayoutSecondName"
android:background="#drawable/field_1"
android:layout_marginTop="20dp"
android:layout_gravity="center">
<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:hint="Identify Family Members In Contacts"
android:maxLines="1"
android:singleLine="true"
android:layout_gravity="center"
android:layout_below="#+id/linearLayoutSecondName"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"
android:background="#android:color/transparent"
android:textSize="12sp"
android:inputType="text" />
</LinearLayout>
<Button android:id="#+id/sign_up_button"
android:layout_width="300dp" android:layout_height="40dp"
android:text="SUBMIT"
android:textColor="#android:color/white"
android:textSize="14sp"
style="?android:attr/borderlessButtonStyle"
android:layout_gravity="center_horizontal|bottom"
android:background="#drawable/rounded_shape"
android:layout_alignParentBottom="false"
android:layout_alignRight="#+id/linearLayout5"
android:layout_alignEnd="#+id/linearLayout5"
android:layout_alignLeft="#+id/linearLayout5"
android:layout_alignStart="#+id/linearLayout5"
android:layout_below="#+id/linearLayout5"
android:layout_marginTop="40dp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
UseScroll View as Your Root Layout.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
Also add this to your Manifest.
<activity android:name="YourActivity"
android:windowSoftInputMode="adjustResize" />
You have to change your layout root to ScrollView Instead of RelativeLayout
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/my_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<!--Your layout components-->
<!--Your layout components-->
</ScrollView
In your manifest.xml add this to your activity
android:windowSoftInputMode="stateHidden|adjustPan"
I just put a linear layout inside a scrollview dont know why its not working.
When the keyboard is open the scrollbar is not showing at all. When i move one text box to another there is a submit button which is not show when i run on small size devices.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/layoutPopUp"
android:layout_width="match_parent"
android:layout_height="79dp"
android:background="#F57F20"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:visibility="visible">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<LinearLayout
android:id="#+id/backlayout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:orientation="horizontal">
<ImageButton
android:id="#+id/btnBackbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:background="#color/transparent"
android:gravity="center"
android:src="#drawable/back"
android:visibility="visible" />
<TextView
android:id="#+id/textBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:gravity="center"
android:text="Back"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="15sp" />
</LinearLayout>
<TextView
android:id="#+id/textTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.6"
android:gravity="center"
android:text="Contact Us"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/imagePopUp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="0.2"
android:background="#color/transparent"
android:gravity="center"
android:src="#drawable/menu"
android:visibility="visible" />
</LinearLayout>
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/editboxshap"
android:ems="10"
android:hint="Name"
android:inputType="textPersonName"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#2b2b2b"
android:textColorHint="#2b2b2b"
android:textCursorDrawable="#color/black">
<requestFocus />
</EditText>
<EditText
android:id="#+id/editPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/editboxshap"
android:ems="10"
android:hint="Phone No."
android:inputType="phone"
android:maxLength="12"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#2b2b2b"
android:textColorHint="#2b2b2b"
android:textCursorDrawable="#color/black" />
<EditText
android:id="#+id/editEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/editboxshap"
android:ems="10"
android:hint="E-mail"
android:inputType="textEmailAddress"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#2b2b2b"
android:textColorHint="#2b2b2b"
android:textCursorDrawable="#color/black" />
<EditText
android:id="#+id/editComment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/editboxshap"
android:ems="10"
android:gravity="start"
android:hint="Comments"
android:inputType="textMultiLine"
android:lines="3"
android:maxLength="500"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#2b2b2b"
android:textColorHint="#2b2b2b"
android:textCursorDrawable="#color/black" />
<Button
android:id="#+id/btnSubmit"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:background="#drawable/button_shape"
android:text="SUBMIT"
android:textColor="#color/white" />
</LinearLayout>
</ScrollView>
</LinearLayout>
try to put scrollview inside another linear layout and try
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/parentLin"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="//define in dp"
android:scrollbars="vertical"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/editboxshap"
android:textColorHint="#2b2b2b"
android:textColor="#2b2b2b"
android:ems="10"
android:hint="Name"
android:inputType="textPersonName"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium">
<requestFocus />
</EditText>
<EditText
android:id="#+id/editPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/editboxshap"
android:ems="10"
android:textColor="#2b2b2b"
android:hint="Phone No."
android:inputType="phone"
android:textColorHint="#2b2b2b"
android:maxLength="12"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/editboxshap"
android:textColor="#2b2b2b"
android:ems="10"
android:textColorHint="#2b2b2b"
android:hint="E-mail"
android:inputType="textEmailAddress"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editComment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/editboxshap"
android:ems="10"
android:gravity="start"
android:textColor="#2b2b2b"
android:hint="Comments"
android:textColorHint="#2b2b2b"
android:inputType="textMultiLine"
android:lines="3"
android:maxLength="500"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center">
<Button
android:id="#+id/btnSubmit"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="5dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/button_shape"
android:text="SUBMIT"
android:textColor="#color/white" />
</RelativeLayout>
</RelativeLayout>
and You have to specify the following line of code in the manifest file with your activity
android:windowSoftInputMode="adjustResize"
try This.. on your activity / fragment
getActivity().getWindow()
.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE |
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
I have a Linear Layout but somehow, no matter what, the login button dose not sits exactly below the text fields. the button always exceeds from the elements.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="${relativePackage}.${activityClass}"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="#string/AppLogDescription"
android:src="#drawable/applogo" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="vertical"
android:layout_below="#+id/imageView1"
android:layout_alignParentBottom="true">
<EditText
android:id="#+id/editText_email"
android:layout_width="272dp"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:drawableLeft="#drawable/mail_icon"
android:drawableStart="#drawable/mail_icon"
android:drawablePadding="10dp"
android:padding="10dp"
android:background="#drawable/edit_text_border"
/>
<EditText
android:id="#+id/editText_Password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
android:drawableLeft="#drawable/password_icon"
android:drawableStart="#drawable/password_icon"
android:background="#drawable/edit_text_border"
android:gravity="center"
android:drawablePadding="5dp"
android:padding="10dp"
android:layout_marginTop="5dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="Name"
android:ems="10"
android:id="#+id/editText"
android:layout_weight="1" />
<Button
android:id="#+id/LogInButton"
android:layout_width="284dp"
android:layout_height="wrap_content"
android:text="#string/LogIn"
android:onClick="LogInClickEvent" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<Switch
android:id="#+id/cb_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="1dp"
android:onClick="RememberMe_click"
android:gravity="center_vertical"
android:switchMinWidth="56dp"
android:textOff=""
android:textOn=""
android:layout_marginTop="10dp"
android:checked="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remember me"
android:layout_marginTop="10dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_weight="0.70" />
<Button
android:id="#+id/TV_LogIn"
android:background="#android:color/transparent"
android:layout_width="wrap_content"
android:layout_height="23dp"
android:text="Forget Password?"
android:textSize="10dp"
android:layout_marginTop="10dp"
android:onClick="ForgetPasswordEvent"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
</RelativeLayout >
</ScrollView>
My text fields seems straight but the buttons (login button and remember me switch) seem to be off grid and a bit more to the right then the fields
Remove your android:padding="10dp" from your second edittext
and android:layout_marginTop="10dp from your button.
And make sure your linearlayout orientation is vertical.
EDIT:
you should use layout_gravity="center" instead of android:layout_centerHorizontal="true" and android:layout_alignParentBottom="true" which are for RelativeLayout
or put your linearLayout inside a RelativeLayout which should be your root layout.
Try this:
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:layout_below="#+id/imageView1"
android:layout_alignParentBottom="true">
<EditText
android:id="#+id/editText_email"
android:layout_width="255dp"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:drawableLeft="#drawable/mail_icon"
android:drawableStart="#drawable/mail_icon"
android:drawablePadding="10dp"
android:padding="10dp"
android:gravity="center"
android:background="#drawable/edit_text_border"
/>
<EditText
android:id="#+id/editText_Password"
android:layout_width="255dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
android:drawableLeft="#drawable/password_icon"
android:drawableStart="#drawable/password_icon"
android:background="#drawable/edit_text_border"
android:gravity="center"
android:drawablePadding="5dp"
android:padding="10dp"
android:layout_marginTop="5dp" />
<Button
android:id="#+id/LogInButton"
android:layout_width="261dp"
android:layout_height="wrap_content"
android:text="#string/LogIn"
android:gravity="center"
android:onClick="LogInClickEvent"
android:layout_marginTop="10dp"
/>
This will not work if you want to put everything on bottom:
android:layout_alignParentBottom="true"
Because it is for RelativeLayout and not for LinearLayout.