UI问题 --- CardView和其它的控件在同一布局中时,始终覆盖其它控件

原本代码:

复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="40dp"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <androidx.cardview.widget.CardView
            android:id="@+id/card_icon"
            android:elevation="0dp"
            android:layout_width="30dp"
            android:layout_height="30dp"
            app:cardCornerRadius="45dp">
            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:src="@drawable/tongji"/>
        </androidx.cardview.widget.CardView>
        <ImageView
            android:id="@+id/more_icon"
            android:elevation="1dp"
            android:layout_width="20dp"
            android:layout_height="10dp"
            android:layout_gravity="bottom||end"
            android:src="@color/money_red"/>
    </FrameLayout>
</LinearLayout>

问题:

card_icon 始终在more_icon之上,但是按照FrameLayout 的特性,最后添加的应该在最上面一层显示。

原因:

CardView 默认会生成阴影效果,这会使其看起来比其他控件高出一层。可以通过 app:elevation 属性或 CardView.setCardElevation() 方法调整 CardView 的高度。

修改后代码:

复制代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="40dp"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <androidx.cardview.widget.CardView
            android:id="@+id/card_icon"
            android:elevation="0dp"
            android:layout_width="30dp"
            android:layout_height="30dp"
            app:cardCornerRadius="45dp">
            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:src="@drawable/tongji"/>
        </androidx.cardview.widget.CardView>
        <ImageView
            android:id="@+id/more_icon"
            android:elevation="2dp"
            android:layout_width="20dp"
            android:layout_height="10dp"
            android:layout_gravity="bottom||end"
            android:src="@color/money_red"/>
    </FrameLayout>
</LinearLayout>
相关推荐
小兔薯了1 天前
7. LNMP-wordpress
android·运维·服务器·数据库·nginx·php
L***d6701 天前
mysql的主从配置
android·mysql·adb
Sammyyyyy1 天前
PHP 8.5 新特性:10 大核心改进
android·php·android studio
TO_ZRG1 天前
Unity 通过 NativePlugin 接入Android SDK 指南
android·unity·游戏引擎
n***84071 天前
Springboot-配置文件中敏感信息的加密:三种加密保护方法比较
android·前端·后端
方白羽1 天前
一次由 by lazy 引发的“数据倒灌”,深入理解 `by`关键字、`lazy`函数的本质
android·kotlin·app
v***55341 天前
MySQL 中如何进行 SQL 调优
android·sql·mysql
vx_vxbs662 天前
【SSM高校普法系统】(免费领源码+演示录像)|可做计算机毕设Java、Python、PHP、小程序APP、C#、爬虫大数据、单片机、文案
android·java·python·mysql·小程序·php·idea
j***82702 天前
【MyBatisPlus】MyBatisPlus介绍与使用
android·前端·后端
ljt27249606612 天前
Compose笔记(五十八)--LinearOutSlowInEasing
android·笔记·android jetpack