【问题标题】:CardView above another CardView with elevation overlappingCardView 在另一个 CardView 上方,高程重叠
【发布时间】:2018-02-26 01:06:17
【问题描述】:

是否可以使用 cardview 标高在布局下方存档。

因为我已经尝试了一些解决方案来存档相同但到目前为止没有成功。

1> 解决方案 1:

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

作为相对布局,最后大多数组件位于所有组件之上,但这不起作用。

2> 解决方案 2:

我尝试在 cardview 下方给出负边距,它仅在 android studio 布局编辑器中显示与上述屏幕类似的内容,当我尝试在真实设备上安装它时,或模拟器布局看起来像下面这样。

【问题讨论】:

    标签: android android-layout android-cardview cardview


    【解决方案1】:

    正如您仅询问 CardView 一样,有一个 hack,这不是正确的方法。如果您可以选择考虑其他方式来实现此布局,我建议您使用额外的 Views 在每个段下方带有阴影(您的问题中的 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"/>
    

    这将产生下面附加的结果

    这个解决方案的问题是,如果你仔细观察,每张卡片的高度都比前一张低。

    【讨论】:

    • 这看起来与我要求感谢此解决方法的内容非常相似。我还将尝试在每个卡片视图下方使用可绘制的解决方案。非常感谢..
    猜你喜欢
    • 2021-11-16
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    • 2020-07-04
    • 2017-07-12
    • 2020-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多