您可以使用FrameLayout重叠视图.在您的布局XML中:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_image"/>
<View
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/my_shape"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
然后res/drawable/my_shape.xml你可以有一个Shape Drawable,例如:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="5dp"/>
<solid android:color="#00000000"/>
<stroke android:width="3dp" android:color="#ffff0000"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
第二个选项是使用自定义视图而不是叠加视图,并覆盖其onDraw方法以执行自定义Canvas绘制.在这种情况下,您仍然可以使用它FrameLayout来定位ImageView上的视图.
第三种选择是使用自定义视图,并使用方法中的drawBitmap调用将图像绘制到其中onDraw.这可能是三种方法中最灵活的.
| 归档时间: |
|
| 查看次数: |
7211 次 |
| 最近记录: |