spinner is not displaying proper while adding blank row - android

I am displaying spinner in recyclerview row. when i add blank row using "Add Member" button, spinner display half like below image
Please help me.i search on google but i didn't get any solution
here is layout for this screen
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/txt_numbertitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:letterSpacing="0.01"
android:lineSpacingExtra="2sp"
android:text="First Member"
android:textColor="#424242"
android:textSize="16sp" />
<ImageView
android:id="#+id/img_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/ic_delete"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<EditText
android:id="#+id/edt_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:backgroundTint="#color/colorPrimary"
android:hint="First Name"
android:inputType="text"
android:maxLines="1"
android:textColor="#color/textcolor"
android:textColorHint="#color/hintcolor" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<EditText
android:id="#+id/edt_surname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#color/colorPrimary"
android:hint="Last Name"
android:inputType="text"
android:maxLines="1"
android:textColor="#color/textcolor"
android:textColorHint="#color/hintcolor" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0">
<Spinner
android:id="#+id/sp_relation"
style="#style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:backgroundTint="#color/colorAccent"
android:dropDownVerticalOffset="35dp"
android:entries="#array/relation"
android:spinnerMode="dropdown"
android:theme="#style/ThemeSpinner" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edt_city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#color/colorPrimary"
android:hint="City"
android:inputType="text"
android:maxLines="1"
android:textColor="#color/textcolor"
android:textColorHint="#color/hintcolor" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
here is a layout for recyclerview row.when is filled data with array, spinner display proper spinner but when i add blank row, it display like below image
<style name="ThemeSpinner">
<!-- Color when pressed -->
<item name="colorAccent">#ffa000</item>
<!-- Default color for the dropdown arrow and line -->
<item name="colorControlNormal">#ffc107</item>
<item name="android:textColor">#color/colorPrimaryDark</item>
</style>
here is theme applied to the spinner

Try changing layout_height value to wrap_content .
If the custom background an xml drawable file check that you aren't using padding at the bottom.

Related

How to work Parent layout click to all child layouts?

In my application, I have a bottom menu So I have implemented the bottom layout for all the screens. I have one red button for the menu visible and gone, This functionality is working fine. But here my one more requirement is when clicking on the screen(outside the menu) a bottom menu will disappear. In my screens so many child layouts are available. here my parent layout is Coordinator layout. So I have created to id to Coordinator layout and Implemented OnClick listener for this one. So In OnClick, I will disappear the menu.
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:id="#+id/coord_layout"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/fgtrellayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="#+id/topBanner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorScreenBG"
android:orientation="horizontal">
<include
android:id="#+id/action_bar"
layout="#layout/custom_action_bar">
</include>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/topBanner"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginBottom="2dp"
android:background="#color/colorScreenBG"
android:orientation="vertical">
<TextView
android:id="#+id/instctsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="1dp"
android:layout_marginRight="7dp"
android:text="#string/forgotPasswordAlert"
android:textColor="#040101"
android:textSize="#dimen/normal_font_size" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<android.support.design.widget.TextInputLayout
style="#style/MyTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="false">
<android.support.design.widget.TextInputEditText
android:id="#+id/fgtActNoVal"
style="#style/MyTextInputEditText"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:hint="#string/acctNo_UserId"
android:imeOptions="actionNext"
android:singleLine="true"
android:inputType="text"
android:maxLength="30"
android:maxLines="1"
android:textColor="#android:color/black"
android:textSize="#dimen/normal_font_size" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
style="#style/MyTextInputLayout"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="false">
<android.support.design.widget.TextInputEditText
android:id="#+id/fgtTelVal"
style="#style/MyTextInputEditText"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:hint="#string/tel_No"
android:imeOptions="actionDone"
android:singleLine="true"
android:inputType="number"
android:maxLength="4"
android:maxLines="1"
android:textColor="#android:color/black"
android:textSize="#dimen/normal_font_size" />
</android.support.design.widget.TextInputLayout>
<TextView
android:layout_gravity="center_horizontal"
android:id="#+id/dgtsLmt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lastFourDigits"
android:textColor="#ff0000"
android:textSize="#dimen/tenfont" />
<CheckBox
android:id="#+id/mailcheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="#string/emailMyPassword"
android:textColor="#040101"
android:textSize="#dimen/normalLayout"
android:visibility="invisible" />
</LinearLayout>
<LinearLayout
android:id="#+id/btnsLayot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp">
<android.support.design.button.MaterialButton
style="#style/MyButton"
android:id="#+id/fgtClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/back"
android:textAllCaps="false"/>
<android.support.design.button.MaterialButton
style="#style/MyButton"
android:id="#+id/fgtReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="#string/reset"
android:textAllCaps="false"/>
<android.support.design.button.MaterialButton
style="#style/MyButton"
android:id="#+id/fgtSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="#string/submit"
android:textAllCaps="false" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<include layout="#layout/bottom_sheet_login"
android:visibility="visible" />
</android.support.design.widget.CoordinatorLayout>``
So in the above xml, Coordinator layout on click is working fine. But if the layout having listview or webview then parent layout on click is not working
This is the xml file
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:id="#+id/coord_layout"
android:background="#color/colorScreenBG"
android:layout_height="fill_parent"
android:layout_marginBottom="0dp"
android:orientation="vertical">
<LinearLayout
android:id="#+id/total_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="60dp"
android:orientation="vertical">
<include
android:id="#+id/topBanner"
layout="#layout/custom_action_bar"></include>
<RelativeLayout
android:id="#+id/NoticeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/locations1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dip"
android:text="#string/noInfoExists"
android:textColor="#C00000"
android:textSize="#dimen/normalHeadings" />
<ListView
android:id="#+id/locations"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="0dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="2dp"
android:background="#00000000"
android:cacheColorHint="#00000000"
android:textColor="#040101" />
</RelativeLayout>
</LinearLayout>
<include
layout="#layout/bottom_sheet_login"
android:visibility="visible" />
</android.support.design.widget.CoordinatorLayout>
In my application, so many screens are there. When clicking on the screen(Outside the menu) the menu will disappear. So how to work parent layout on click for all the child views.
Check the bellow image
So please help with this.
Thanks In Advance
First, add those to your root view for touchable area.
android:focusableInTouchMode="true"
android:clickable="true"
android:focusable="true"
After that, you can use onFocusChanged listener to handle your views' behaviour.

Input styling is not uniform

Check out how ugly this is:
Here is my XML:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="20dp"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="Style"
android:textSize="18sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Position" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/array_positions"
android:layout_marginBottom="20dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Icon Color" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:text="red"/>
</LinearLayout>
How do I make it so the spinner and edittext always look the same? I've even tried adding style="#style/Widget.AppCompat.Spinner.Underlined" to the spinner, and while it add the bottom line, the padding and font size is still different.

How to align Ui Components inside linear layout

Hi All could someone direct me on how i could align the Spinners and Edit text attached in the screen
Thank you for your help
XML file - below is the layout XML file for the UI screen
<LinearLayout 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:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context="eudhar.com.eudhar.transaction.MakeTransactionFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Make Transaction"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
style="#style/Base.V7.Widget.AppCompat.EditText"/>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.toptoche.searchablespinnerlibrary.SearchableSpinner
android:id="#+id/selectCustomer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Select customer"
style="#style/Base.Widget.AppCompat.Spinner.Underlined"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Spinner
android:id="#+id/selectTransactionType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Select Transaction Type"
style="#style/Base.Widget.AppCompat.Spinner.Underlined"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_amount"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/editTextAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Amount in Rs."
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:inputType="number" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/editTextTransactionDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Transaction Date"
android:inputType="none"
/>
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/buttonAddTrasaction"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add Transaction" />
</LinearLayout>
Give margin to your Linear /Relative layout, else share your code, so I can easily give you the answer.
Is this okay?
Try this below code, i have given paddingLeft and paddingRight "5dp" to the parent layout itself. You may adjust as you need.
<LinearLayout 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:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:paddingLeft="5dp"
android:paddingRight="5dp"
tools:context="eudhar.com.eudhar.transaction.MakeTransactionFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Make Transaction"
android:textAppearance="#style/Base.TextAppearance.AppCompat.Small"
style="#style/Base.V7.Widget.AppCompat.EditText"/>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.toptoche.searchablespinnerlibrary.SearchableSpinner
android:id="#+id/selectCustomer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Select customer"
style="#style/Base.Widget.AppCompat.Spinner.Underlined"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Spinner
android:id="#+id/selectTransactionType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="Select Transaction Type"
style="#style/Base.Widget.AppCompat.Spinner.Underlined"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_amount"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/editTextAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Amount in Rs."
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:inputType="number" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/editTextTransactionDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Transaction Date"
android:inputType="none"
/>
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/buttonAddTrasaction"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add Transaction" />
</LinearLayout>

Edit text fields snapping into view

So I've been designing in XML in Android Studio a standard log in page - with an image covering about half of the screen, and then the edit text fields occupying the bottom half, asking for the log in details. My problem is that when I tap on the edit text fields on smaller mobile displays, it will only snap to and show the field I have selected, when I think it's far better if it were to automatically snap to show all fields and the 'Next' button at once.
An overview of the page
When I click on 'UserID' field
What I WANT to see when I click on 'UserID' field
How do I achieve this result?
<LinearLayout 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:gravity="center_horizontal"
android:orientation="vertical"
tools:context="com.example.android.brunelplanner.LoginActivity">
<!-- Login progress -->
<ProgressBar
android:id="#+id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ScrollView
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/logo"
android:layout_width="match_parent"
android:layout_height="250sp"
android:background="#color/colorPrimary"
android:orientation="vertical"></LinearLayout>
<RelativeLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/logo"
android:orientation="vertical">
<LinearLayout
android:id="#+id/login_fields"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.87"
android:gravity="center"
android:text="eVision Log in"
android:textColor="#000000"
android:textSize="20sp" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_userID"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/prompt_password"
android:imeActionId="#+id/login"
android:imeActionLabel="#string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/login_fields">
<Button
android:id="#+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="#string/action_sign_in"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
Cant comment so I have to write here. If you XML in question is current, you have to align parent bottom the whole layout that you want to move up. The bottom alignment must have the whole login form not just button. Also you have linear layout on top which has fixed height, that could be a problem too.
EDIT: Ok, try this, it works on my end. BUT I simplified the XML for testing so dont copy it, just try to edit your xml.
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/email_login_form"
android:layout_alignParentTop="true"
android:background="#color/colorPrimary"
android:orientation="vertical">
</LinearLayout>
<RelativeLayout
android:id="#+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true">
<LinearLayout
android:id="#+id/login_fields"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.87"
android:gravity="center"
android:text="eVision Log in"
android:textColor="#000000"
android:textSize="20sp" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/email_login_form"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:text="sign in"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>

No shadow/elevation underneath second card if there are two card in the layout. Why?

I have 2 cards in a single RelativeLayout.
The problem is that there is no elevation or shadow underneath the second card.
See the screenshot here: screenshot
Here's what I have done in the xml file:
<?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="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.abc.xyz.abcActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/cba_screen_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/cba_screen_text"
android:textColor="#android:color/white"
android:textSize="#dimen/cba_screen_text"
android:gravity="center_horizontal|center_vertical"
android:layout_gravity="center_horizontal|center_vertical"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/signup_screen_first_cardview_top_margin"
app:contentPadding="10dp"
app:cardBackgroundColor="#android:color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:orientation="vertical">
<!-- N Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/abc_screen_name_label_topmargin">
<EditText android:id="#+id/input_n"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapWords"
android:textColor="#color/colorPrimary"
android:hint="N" />
</android.support.design.widget.TextInputLayout>
<!-- E Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/abc_screen_name_label_topmargin"
android:layout_marginBottom="#dimen/abc_screen_name_label_topmargin">
<EditText android:id="#+id/input_e"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapWords"
android:textColor="#color/colorPrimary"
android:hint="E" />
</android.support.design.widget.TextInputLayout>
<!-- P Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/abc_screen_name_label_topmargin"
android:layout_marginBottom="#dimen/abc_screen_name_label_topmargin">
<EditText android:id="#+id/input_p"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapWords"
android:textColor="#color/colorPrimary"
android:hint="P"/>
</android.support.design.widget.TextInputLayout>
<!-- S Button -->
<android.support.v7.widget.AppCompatButton
android:id="#+id/btn_s"
android:layout_width="#dimen/s_btn_width"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/c_btn_topmargin"
android:layout_gravity="center_horizontal"
android:padding="12dp"
android:text="C"
android:textSize="#dimen/s_btn_text_size"/>
<TextView android:id="#+id/l"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/a_topmargin"
android:text="A"
android:gravity="center"
android:textSize="16sp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_gravity="center_horizontal|center_vertical"
android:text="OR"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="#android:color/white"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentPadding="10dp"
app:cardElevation="2dp"
app:cardBackgroundColor="#android:color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.gms.common.SignInButton
android:id="#+id/google_login_button"
android:layout_width="#dimen/sign_in_btn_width"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
<com.facebook.login.widget.LoginButton
android:id="#+id/facebook_login_button"
android:layout_width="#dimen/sign_in_btn_width"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</RelativeLayout>
Please let me know why is this happening and how can I have the shadow/elevation underneath the second card too?
Your LinearLayout is wrapping its height, cutting off the shadow of the card at the bottom.
Either put some padding on the bottom of the LinearLayout or set it to match_parent on its height.
PS that outer RelativeLayout is useless -- get rid of it and put all the padding and background on the inner LinearLayout

Categories

Resources