有的时候,我们需要一个View覆盖在另外一个View上,并且需要这个View覆盖于另一个View特定的位置
下面根据实现一个类似于其它App上的历史记录标签或者热点标签的Demo来讲解
示例:
想实现上面这种效果,首先要分清button与其右上角的deleteView的位置关系,从图中可以看出,deleteView的中心是button的右上角
所以,可以让deleteView的右边与button的右边相等(这样deleteView的右边就是由button的右边来限制),然后deleteView距离右边-15dp
deleteView的上边与button的上边相等,然后距离上边-15dp,好了,贴上代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
an

本文通过一个示例介绍了如何在Android中实现一个View覆盖在另一个View上,特别是创建类似历史记录或热点标签的效果。关键在于利用RelativeLayout的层叠顺序,使新增的删除按钮位于Button的右上角,通过设置相对位置达到需求效果。
最低0.47元/天 解锁文章
7万+

被折叠的 条评论
为什么被折叠?



