CardView上面另一个CardView与海拔重叠

时间:2017-09-17 10:54:57

标签: android android-layout android-cardview cardview

是否可以使用cardview高程存档到布局下方。 enter image description here

由于我尝试了很少的解决方案来存档,但目前没有成功。

1>解决方案1:

<RelativeLayout>
<AccountCardView>
<ChangePasswordCardView>
<EmailCardView>

作为相对布局的最后一个组件是最重要的,但这不起作用。

2 - ;解决方案2:

我尝试给予负余量到cardview以下它只显示在android studio布局编辑器中的一些类似于上面的屏幕,当我尝试在真实设备上安装它或模拟器布局似乎看起来像下面一个。 enter image description here

1 个答案:

答案 0 :(得分:1)

由于您只询问了CardView,因此存在黑客攻击,这不是正确的方法。如果您可以选择考虑其他方式来实现此布局,我建议您使用额外的 视图 ,并在每个细分下方使用投影(问题中的CardView)。

请尝试以下方法与CardView实现相同的目标

<?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="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto">


<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:id="@+id/card_1"
    android:layout_height="100dp"
    card_view:cardElevation="15dp"
    card_view:cardPreventCornerOverlap="false"/>

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:id="@+id/card_2"
    android:layout_height="100dp"
    card_view:cardElevation="14dp"
    android:layout_below="@+id/card_1"
    card_view:cardPreventCornerOverlap="false"/>

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:id="@+id/card_3"
    android:layout_height="100dp"
    card_view:cardElevation="13dp"
    android:layout_below="@+id/card_2"
    card_view:cardPreventCornerOverlap="false"/>

这将产生下面附带的结果

enter image description here

此解决方案的问题在于,如果您仔细注意,每张卡片的高度都比前一张卡片低。