[英]Set border for view with an icon in the corner
我想添加一个边框以查看在角落中有一个图标的边框,如下所示:
我写了一个带边框的drawable:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@android:color/transparent" />
<stroke
android:width="2dp"
android:color="#F62626"
android:dashWidth="3dp"
android:dashGap="7dp" />
这可以使用 layer-list、drawable 和属性(如 adroid:top、left、right、bottom)来实现。 像这样的东西:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_lock"
android:top="-10dp"
android:left="-10dp"/>
<item
android:left="10dp"
android:top="10dp"
android:bottom="10dp"
android:right="10dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@android:color/transparent" />
<stroke
android:width="2dp"
android:color="#F62626"
android:dashWidth="3dp"
android:dashGap="7dp" />
</shape>
</item>
</layer-list>
另一种方法是使用 ConstraintLayout 并将图标作为单独的视图放在那里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.