ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

android – 如果布局中有两张卡,则第二张卡下面没有阴影/高度.为什么?

2019-09-25 20:35:35  阅读:224  来源: 互联网

标签:android material-design android-cardview android-xml


我在一个RelativeLayout中有2张牌.

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

请参见此处的屏幕截图:screenshot

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

<?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>

请让我知道为什么会发生这种情况,我怎样才能在第二张卡下面留下阴影/高度?

解决方法:

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

在LinearLayout的底部放置一些填充或在其高度上将其设置为match_parent.

外部RelativeLayout的PS是无用的 – 摆脱它并将所有填充和背景放在内部LinearLayout上

标签:android,material-design,android-cardview,android-xml
来源: https://codeday.me/bug/20190925/1816801.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有