長さが足りない素材で、セパレーターを画面の幅いっぱいに広げるテクニック。
下の画像は、上側のセパレーターが広げたもので、下のセパレーターが素材のままです。
layout.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" >
<ImageView
android:id="@+id/separator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/separator"
android:scaleType="fitXY"
android:src="@drawable/separator_repeat" />
</LinearLayout>
separator_repeat.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/separator"
android:dither="true"
android:tileMode="mirror" />
肝はbitmapのtileModeと、ImageViewのscaleTypeです。
tileMode="mirror"は左右を反転しながら繰り返し表示をしてくれるので、繋ぎ目が目立ちにくくなります。
scaleType="fitXY"は、指定しないとImageViewが画面いっぱいに広がっていても、画像は広がってくれません。指定すれば、タイル表示が有効になります。
タグ: tips

HOMMA Teppei

