<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/test"
android:antialias="true"
android:dither="true"
android:filter="true"
android:gravity="clip_vertical"
android:tileMode="disabled"/>
bitmap_drawable2.xml:查看clip_horizontal效果
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/test"
android:antialias="true"
android:dither="true"
android:filter="true"
android:gravity="clip_horizontal"
android:tileMode="disabled"/>
bitmap_drawable3.xml:查看clamp效果
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/test"
android:antialias="true"
android:dither="true"
android:filter="true"
android:tileMode="clamp"/>
bitmap_drawable4.xml:查看mirror效果
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/test"
android:antialias="true"
android:dither="true"
android:filter="true"
android:tileMode="mirror"/>
test.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="50dp"
android:layout_height="100dp"
android:background="@drawable/bitmap_drawable" />
<FrameLayout
android:layout_width="100dp"
android:layout_height="50dp"
android:background="@drawable/bitmap_drawable2">
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/bitmap_drawable3">
</FrameLayout>
</LinearLayout>
test.xml的效果图:
可以看到:clip_vertical时,图片等比例缩放(这里是缩小)后,纵向填满,横向被切;
clip_horizontal时,图片等比例缩放(这里是缩小)后,横向填满,纵向被切;
clamp情况下,图片四周(本例中只有底部有未填充的区域)的最后一个像素的颜色被重复填充在控件未填充的区域
将最后一个FrameLayout 的background 改为bitmap_drawable4
效果图为: