android图片的覆盖,Android – ImageView覆盖另一个ImageView

本文提供了一种改进的答案,提出一个不需调整布局或等分屏幕的解决方案,适用于垂直方向的视图。主要讨论了如何使用`match_parent`和`wrap_content`来创建一个清晰布局,包括带有图片叠加的两部分布局,适合Android应用设计。

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

我得到了很多关于这个答案的赞成.所以我试着改善这个答案.可能这是与其他两个相比更好的方法,因为这个解决方案不需要修复布局或将屏幕分成相等的部分,所以可能这样做更好.

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

android:id="@+id/viewA"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@color/colorPrimary"

android:orientation="horizontal">

android:id="@+id/subject"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:padding="20dp"

android:text="Thi"

android:textColor="@android:color/white"

android:textSize="17sp"

/>

android:id="@+id/viewB"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@android:color/white"

android:orientation="horizontal">

android:id="@+id/description"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:padding="20dp"

android:text="Thi"

android:textColor="@android:color/black"

android:textSize="17sp"

/>

android:id="@+id/fab"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="16dp"

android:clickable="true"

android:src="@drawable/plus"

app:layout_anchor="@+id/viewA"

app:layout_anchorGravity="bottom|right|end"/>

替代方式试试这个

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

// this is your first layout to put the big image

// use src or backgroud image as per requirement

android:background="@color/red_error"

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_weight="1">

// this is your bottom layout

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_weight="1">

// This is the imageview which overlay the first LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/success"

android:adjustViewBounds="true"

android:layout_gravity="center"/>

它看起来像这样

mLIHC.png

找到了另一个解决方案(编辑)

如果您的大图像尺寸是固定高度,您可以试试这个

android:layout_width="match_parent"

android:layout_height="match_parent" >

android:id="@+id/layoutTop"

android:background="@color/red_error"

android:layout_width="match_parent"

android:layout_height="200dp" >

android:id="@+id/layoutBottom"

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_alignParentBottom="true"

android:layout_below="@id/layoutTop" >

android:id="@+id/overlapImage"

android:layout_width="wrap_content"

android:layout_height="40dp"

android:layout_above="@id/layoutBottom"

android:layout_centerHorizontal="true"

android:layout_marginBottom="-20dp"

android:adjustViewBounds="true"

android:src="@drawable/testimage" />

希望这会有所帮助.祝你好运

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值