如果布局中有两张卡片,则第二张卡片下方没有阴影/高度.为什么? [英] No shadow/elevation underneath second card if there are two card in the layout. Why?

查看:32
本文介绍了如果布局中有两张卡片,则第二张卡片下方没有阴影/高度.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个 RelativeLayout 中有 2 个 cards.

I have 2 cards in a single RelativeLayout.

问题是第二张卡片下面没有高程或阴影.

The problem is that there is no elevation or shadow underneath the second card.

在此处查看屏幕截图:屏幕截图

这是我在 xml 文件中所做的:

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?

推荐答案

你的 LinearLayout 正在包裹它的高度,切断底部卡片的阴影.

Your LinearLayout is wrapping its height, cutting off the shadow of the card at the bottom.

要么在 LinearLayout 的底部放置一些填充,要么将其设置为 match_parent 的高度.

Either put some padding on the bottom of the LinearLayout or set it to match_parent on its height.

PS外面的RelativeLayout没用——去掉它,把所有的内边距和背景放在里面的LinearLayout上

PS that outer RelativeLayout is useless -- get rid of it and put all the padding and background on the inner LinearLayout

这篇关于如果布局中有两张卡片,则第二张卡片下方没有阴影/高度.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆