需求
现在有一个需求就是希望实现一个这样的布局,并且支持数据配置多项
所以我把里面部分封装成了一个继承ViewGroup的自定义View,布局代码如下:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:layout_marginTop="-10dp"
android:layout_marginRight="-10dp"
android:src="@drawable/red_dot"
android:visibility="gone"
tools:visibility="visible" />
</FrameLayout>
主要是小红点上边距和右边距为负数,然后在具体引用地方的爷爷结点使用android:clipChildren="false"
,但是发现上边突出的部分还是无法显示,通过网上查找才知道爷爷结点不能使用padding属性,如果需要使用的话需要设置android:clipToPadding="false"