adjustPan not properly resizing screen - android

I have a layout with Text,2 Spinners, 1 EditText and 1 Button on the end. When i want to enter something in EditText that button get covered by Keyboard.
This is Fragment not Activity if it's making any difference.
<?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="fill_parent"
android:background="#color/transparentlightgrey">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/SectionName"
android:layout_width="fill_parent"
android:layout_height="56dp"
android:background="#color/neonGreen"
android:textColor="#C6D600"
android:textSize="20sp"
android:textStyle="normal|bold">
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="false"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Add Credit"
android:textColor="#color/lightGrey"
android:textSize="20dp"
android:textStyle="bold" />
</RelativeLayout>
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/AddPointsHolder"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp"
android:orientation="vertical">
<Spinner
android:id="#+id/spinneroperater"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="#d8d8d8"
android:spinnerMode="dialog" />
<Spinner
android:id="#+id/spinnerTopUp"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="#d8d8d8"
android:spinnerMode="dialog"
android:touchscreenBlocksFocus="false" />
<EditText
android:id="#+id/phoneNumber"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_below="#+id/linearLayout"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/edit_text_border"
android:ems="10"
android:hint="Enter Phone number"
android:inputType="number"
android:maxLength="12"
android:paddingLeft="5dp"
android:textColor="#ffffff"
android:textColorHint="#ffffff"
android:textSize="18dp" />
</LinearLayout>
<TextView
android:id="#+id/AddPointsHolder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/SectionName"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:text="#string/addPoints"
android:textColor="#ffffff" />
<Button
android:id="#+id/addPoints"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:background="#drawable/rounded_button_clickable"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Add Credit" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>

adjustPan doesn't resize the screen. Since you have a scrolling view, you should be using adjustResize.
From the docs on 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.

Do this.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:background="#color/white"
android:orientation="vertical">
<ScrollView
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Credit"
android:id="#+id/textView14"
android:textColor="#color/lightGrey"
android:textSize="20dp"
android:textStyle="bold"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="false"
android:layout_marginLeft="10dp" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/AddPointsHolder"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout"
android:layout_marginTop="10dp">
<Spinner
android:layout_width="fill_parent"
android:layout_height="40dp"
android:id="#+id/spinneroperater"
android:spinnerMode="dialog"
android:layout_weight="1"
android:background="#d8d8d8"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<Spinner
android:layout_width="fill_parent"
android:layout_height="40dp"
android:id="#+id/spinnerTopUp"
android:spinnerMode="dialog"
android:layout_weight="1"
android:layout_marginTop="10dp"
android:background="#d8d8d8"
android:touchscreenBlocksFocus="false"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp" />
<EditText
android:layout_width="fill_parent"
android:layout_height="40dp"
android:inputType="number"
android:ems="10"
android:id="#+id/phoneNumber"
android:hint="Enter Phone number"
android:background="#drawable/edit_text_border"
android:textSize="18dp"
android:paddingLeft="5dp"
android:layout_below="#+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp"
android:maxLength="12"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/addPoints"
android:id="#+id/AddPointsHolder"
android:layout_below="#+id/SectionName"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textColor="#ffffff" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Credit"
android:id="#+id/addPoints"
android:layout_below="#+id/linearLayout"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:background="#drawable/rounded_button_clickable"
android:paddingRight="10dp"
android:paddingLeft="10dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>

Related

ScrollView.FOCUS_UP not working in my project with root layout as scrollView

I know it is silly question but i used many solution which already given by stack Overflow but no one solve my problem, my question is, I want to Scroll Up the layout after clicking on last edittext because keyboard hide the EditText and i am unable to see what is typing..
Code I am using in onCreate method
scrollView=(ScrollView)findViewById(R.id.activityRoot);
addressEdt=(EditText)findViewById(R.id.profilAddress);
addressEdt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
scrollView.fullScroll(ScrollView.FOCUS_UP);
}
});
My xml code is
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:id="#+id/activityRoot">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/colorWhite">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:layout_marginTop="10dp"
android:id="#+id/linearLayout7">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/driverName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|bottom"
android:layout_marginTop="90dp"
android:gravity="center"
android:padding="5dp"
android:text="Kevin Michaels"
android:textSize="18dp" />
<TextView
android:id="#+id/total_rides_editProfile"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|bottom"
android:layout_marginTop="140dp"
android:gravity="center"
android:padding="5dp"
android:text=""
android:textSize="17dp" />
<com.mikhaellopez.circularimageview.CircularImageView
android:id="#+id/userProfileImageView"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="center_horizontal|top"
android:scaleType="centerCrop"
android:src="#drawable/profile_user_icon" />
<ProgressBar
android:id="#+id/profileImageProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp" />
<ImageView
android:id="#+id/userChangePhotoButton"
android:layout_width="37dp"
android:layout_height="37dp"
android:layout_gravity="right|top"
android:src="#drawable/camera_icon" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
android:layout_below="#+id/linearLayout7">
<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:hint="Username"
android:paddingLeft="15dp"
android:paddingRight="60dp"
android:layout_marginTop="7dp"
android:gravity="center"
android:maxLength="20"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
style="#style/ProfileUserNameEditText"
android:singleLine="true"
android:id="#+id/txtprofileUserName"/>
<EditText
style="#style/ProfileMobileNumberEditText"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/profileMobile"
android:layout_gravity="center_horizontal"
android:hint="Mobile"
android:paddingLeft="15dp"
android:paddingRight="60dp"
android:layout_marginTop="7dp"
android:gravity="center"
android:maxLength="10"
android:singleLine="true"
android:inputType="phone|textPhonetic"/>
<EditText
style="#style/ProfileAddressEditText"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/profilAddress"
android:layout_gravity="center_horizontal"
android:hint="Address"
android:inputType="text"
android:paddingLeft="15dp"
android:paddingRight="60dp"
android:layout_marginTop="7dp"
android:gravity="center"
android:singleLine="true"
android:maxLines="1"
android:drawableLeft="#drawable/edit_profile_address"
android:maxLength="40"
/>
<TextView
style="#style/ProfileEmailEditText"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/profileEmail"
android:layout_gravity="center_horizontal"
android:hint="Email"
android:paddingLeft="15dp"
android:paddingRight="60dp"
android:layout_marginTop="7dp"
android:gravity="center"
android:singleLine="true" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/saveProfileButton"
android:background="#drawable/a_log_in_button"
android:text="Done"
android:textColor="#color/white"
android:layout_marginTop="10dp"
android:textSize="17dp"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

Stop edittext gaining focus with scroll view in activity - android

There are many questions and answers about how to stop an edittext gaining focus on activity startup.
However, all of the solutions do work for me and the edittext doesn't gain focus at start up, but this stops the scroll view from scrolling.
I tried almost all of the solutions in the post:
Stop EditText from gaining focus at Activity startup
and it doesn't work with scroll view in the activity.
This is causing me much trouble. Any help would be great.
Thanks
Tried the following:
Dummy item to prevent AutoCompleteTextView from receiving focus
Set attributes of edit text: Set the attributes android:focusable="true" and android:focusableInTouchMode="true"
Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/content_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_home">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:fitsSystemWindows="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:visibility="gone" />
<TextView
android:id="#+id/textViewLinkToOrder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="Click here to book travel insurance."
android:textColor="#color/colorPrimary"
android:textSize="24sp"
/>
<LinearLayout
android:id="#+id/buttons_linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/textViewLinkToOrder"
android:orientation="horizontal">
<Button
android:id="#+id/choose_country_button"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="#id/textViewLinkToOrder"
android:layout_centerHorizontal="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="#color/colorPrimary"
android:onClick="onChooseCountryButtonClick"
android:text="Choose country"
android:textColor="#ffff" />
<Button
android:id="#+id/automatic_country_button"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="#id/choose_country_button"
android:layout_centerHorizontal="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="#color/colorPrimary"
android:text="My Location"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutAllDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/buttons_linear_layout"
android:orientation="vertical">
<TextView
android:id="#+id/textView_coumtry_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
android:text="No country yet selected"
android:textColor="#000000"
android:textSize="30sp"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e8e8e8"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextFromCurrency"
android:layout_width="80sp"
android:layout_height="50sp"
android:background="#drawable/edit_txt_bg"
android:ems="10"
android:inputType="number"
android:text="1" />
<TextView
android:id="#+id/textViewFromCurrency"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:gravity="center"
android:text="None"
android:textColor="#000000"
android:textSize="17sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<EditText
android:id="#+id/editTextToCurrency"
android:layout_width="80sp"
android:layout_height="50sp"
android:background="#drawable/edit_txt_bg"
android:ems="10"
android:inputType="number"
android:text="1" />
<TextView
android:id="#+id/textViewToCurrency"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:gravity="center"
android:text="New Israeli Shekel"
android:textColor="#000000"
android:textSize="17sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="20dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/police" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="Police"
android:textColor="#000000"
android:textSize="17sp" />
<TextView
android:id="#+id/police_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text=""
android:textColor="#000000"
android:textSize="17sp" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageView
android:id="#+id/police_phone_button"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:src="#android:drawable/sym_action_call" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="20dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/ambulance" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="Ambulance"
android:textColor="#000000"
android:textSize="17sp" />
<TextView
android:id="#+id/ambulance_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text=""
android:textColor="#000000"
android:textSize="17sp" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageView
android:id="#+id/ambulance_phone_button"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:src="#android:drawable/sym_action_call" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="20dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/israel_consulate" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="Israel Consulate"
android:textColor="#000000"
android:textSize="17sp" />
<TextView
android:id="#+id/israel_consulate_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text=""
android:textColor="#000000"
android:textSize="17sp" />
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageView
android:id="#+id/israel_phone_button"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:src="#android:drawable/sym_action_call"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="20dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/chabad" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="Chabad"
android:textColor="#000000"
android:textSize="17sp" />
<TextView
android:id="#+id/chabad_number_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text=""
android:textColor="#000000"
android:textSize="17sp" />
<TextView
android:id="#+id/chabad_address_text_view"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text=""
android:textColor="#000000"
android:textSize="13sp" />
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageView
android:id="#+id/chabad_phone_button"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:src="#android:drawable/sym_action_call" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
One alternative to get the result you want is hide the device's virtual keyboard. This will inhibit the EditText to gain focus thus not scrolling the screen. You can achieve this with this function:
public static void hideKeyboard(Activity activity) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
//Find the currently focused view, so we can grab the correct window token from it.
View view = activity.getCurrentFocus();
//If no view currently has focus, create a new one, just so we can grab a window token from it
if (view == null) {
view = new View(activity);
}
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
Called this way: hideKeyboard(this);, preferentially inside your onCreate() method.
If user taps EditText, virtual keyboard is showed again.

a linear layout does not seems straight

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.

how do i use both scroll view and RecyclerView in one xml layout android?

In my application i am using recycler view and scrollview in one layout. it is not working when i am using both these views. If i remove scroll view only the recycler view is working. Plese any one help me hoe to fix this issue.
my code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/r1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
>
<ScrollView
android:id="#+id/sc"
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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1e356a">
<TextView
android:id="#+id/placce_head"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="Hyderabad to banglore"
android:textColor="#ffffff"
android:textSize="20dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#78869c"
android:weightSum="2"
android:orientation="horizontal">
<TextView
android:id="#+id/seats"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Selected Seats"
android:textColor="#ffffff"
android:textSize="16dp" />
<TextView
android:id="#+id/totalamount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Total Amount"
android:textColor="#ffffff"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#78869c"
android:weightSum="2"
android:orientation="horizontal">
<TextView
android:id="#+id/seat_num"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:textColor="#ffffff"
android:textSize="16dp" />
<TextView
android:id="#+id/total_amount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#ffffff"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/boardingpoint_edttxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:layout_marginLeft="30dp"
android:layout_marginTop="22dp"
android:background="#null"
android:hint=" Select Boarding Point"
android:textColorHint="#1e365a"
android:textSize="15dp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="7dp"
android:background="#1e365a" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#78869c"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/contact_details"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="Contact Details"
android:textColor="#ffffff"
android:textSize="20dp" />
</RelativeLayout>
<EditText
android:id="#+id/contactname_edt_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="22dp"
android:background="#null"
android:hint="Contact Name"
android:textColorHint="#1e365a"
android:textSize="15dp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="7dp"
android:background="#1e365a" />
<EditText
android:id="#+id/email_edt_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="22dp"
android:background="#null"
android:hint="Email Address"
android:textColorHint="#1e365a"
android:textSize="15dp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="7dp"
android:background="#1e365a" />
<EditText
android:id="#+id/contactnum_edt_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="22dp"
android:background="#null"
android:hint="Contact Number"
android:textColorHint="#1e365a"
android:textSize="15dp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="7dp"
android:background="#1e365a" />
<EditText
android:id="#+id/emergency_edt_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="22dp"
android:background="#null"
android:hint="Emergency Contact Number"
android:textColorHint="#1e365a"
android:textSize="15dp" />
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="7dp"
android:background="#1e365a" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#78869c"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/passenger_details"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="Passenger Details"
android:textColor="#ffffff"
android:textSize="20dp" />
</RelativeLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/view"
android:layout_below="#+id/sc"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<LinearLayout
android:id="#+id/coupon_lay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="8dp"
android:layout_marginTop="12dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="100" >
<EditText
android:id="#+id/entercouponcode_edt"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="50"
android:hint="Enter coupn code"
android:inputType="text" >
<requestFocus />
</EditText>
<Button
android:id="#+id/bt_apply"
style="#style/payment_button_style"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="-5dp"
android:layout_weight="40"
android:gravity="center"
android:text="Apply" />
</LinearLayout>
<Button
android:id="#+id/pay_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:background="#F93249"
android:duplicateParentState="true"
android:gravity="center"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="Proceed to Pay"
android:textColor="#ffffff"
android:textSize="20dp"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
you must know that ,your scrollview property is set as MatchParent ,which means it will fill the content view, so i suggest to set Height a real value such as 100dp, and it will work
You need to dynamically change the height of the recyclerview, depending on how many items you have.
int recyclerheight = height_per_item * adapterData.size();
recyclerView.getLayoutParams().height = recyclerheight;
The scroll view blocks the recyclerview from changing its height set in the xml, that's why you need to do it programically.

Android widget not showing up on the emulator screen

I have added some widgets on activity_main.xml, a layout file for main.java in android. When I ran the program on emulator, the last widget is missing in the emulator screen. What will be the reason? How to rectify it?
Here by I am giving below the code for activity_main.xml
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg1"
android:paddingBottom="50dp">
<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:layout_marginTop="0dp"
android:src="#drawable/cmplnlogo"
android:id="#+id/imageViewLogo" />
<EditText
android:layout_marginTop="30dp"
android:layout_width="310dp"
android:layout_height="50dp"
android:layout_marginLeft="30dp"
android:inputType="textEmailAddress"
android:hint="#string/signupUserHint"
android:textSize="15sp"
android:gravity="center"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textColorHint="#FFFFFF"
android:background="#drawable/edittextstyle"
android:ems="10"
android:id="#+id/editTextEmail" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF00FF"
android:id="#+id/textViewEmailValidator" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:gravity="center"
android:hint="#string/signupPwd"
android:textColorHint="#FFFFFF"
android:inputType="textPassword"
android:background="#drawable/edittextstyle"
android:ems="10"
android:id="#+id/editTextPwd" />
<EditText
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:textColor="#FFFFFF"
android:textSize="15sp"
android:gravity="center"
android:hint="#string/signupCfmPwd"
android:textColorHint="#FFFFFF"
android:inputType="textPassword"
android:background="#drawable/edittextstyle"
android:ems="10"
android:id="#+id/editTextConfirmPwd" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF00FF"
android:id="#+id/textViewPwdValidator" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/signInHint"
android:onClick="GoToLogin"
android:textColor="#FFFFFF"
android:id="#+id/textViewSignin" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/edittextstyle"
android:text="#string/SignUp"
android:onClick="SignUp"
android:textColor="#FFFFFF"
android:id="#+id/buttonSignUp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/service_terms"
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/textViewServiceTerms" />
</LinearLayout>
</LinearLayout>
I solved the problem mentioned in the above question by adding scrollview widget. I added the scrollview widget in the layout file for which all widgets are not appearing on the emulator. Remember scrollview only suppors only one direct file.
I had many layouts inside the layout file that enclosed different widgets. I enclosed all the layouts with in one layout. And then, enclosed that layout with scrollview. I am giving the snippet.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#+id/scroll">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/username"
android:id="#+id/registerUserName"
android:paddingBottom="10dp"
android:layout_weight="1"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/enterRegisterUserName"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</Scrollview>

Categories

Resources