android:elevation 使用小问题记录,底部没有阴影问题,上左右都有阴影

本文探讨了在对话框布局中,如何利用`android:elevation`实现元素立体感,同时处理wrap_content高度下视图层次问题。作者介绍了使用占位视图的方法,并提到了避免`match_parent`带来的问题。核心在于理解和应用约束布局技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

item_chat_text_right.xml

<androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/ivIcon"
            android:layout_width="46dp"
            android:layout_height="46dp"
            android:layout_marginTop="12dp"
            android:layout_marginRight="@dimen/chat_margin_h"
            app:imageTransform="@{ImageTransform.ROUNDED_CORNERS}"
            app:imageUrl="@{userMine.userIcon}"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:src="@android:drawable/sym_def_app_icon" />

        <TextView
            android:id="@+id/tvMsg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/item_chat_dialog_margin_h"
            android:background="@drawable/bg_chat_right_box"
            android:elevation="3dp"
            android:paddingLeft="14dp"
            android:paddingTop="14dp"
            android:paddingRight="20dp"
            android:paddingBottom="16dp"
            android:text="@{item.msg}"
            android:textColor="#000000"
            android:textSize="16sp"
            app:layout_constrainedWidth="true"
            app:layout_constraintHorizontal_bias="1"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toLeftOf="@id/ivIcon"
            app:layout_constraintTop_toTopOf="@id/ivIcon"
            tools:text="我是谁,我来自哪里,我要去往何方?我是谁,我来自哪里,我要去往何方?" />


    </androidx.constraintlayout.widget.ConstraintLayout>

android:elevation=“3dp”
如果父布局使用 android:layout_height=“wrap_content”,那么使用android:elevation底部应该还有其他view,底部可添加占位view

<View
            android:layout_height="2dp"
            android:layout_width="match_parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tvMsg" />

或者 android:layout_height=“match_parent”,这种方式有其他问题,不建议使用。解决一个问题,引出其他问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值