BitmapDrawable はコードからも生成できますが、xml で作ったほうが楽です。 Bitmap Resource の XML Bitmap のところを参照してね。
XML ファイルは
res/drawable/filename.xml
XML ファイルの中身の SYNTAX
- <!--xml version="1.0" encoding="utf-8"?-->
- <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
- android:src="@[package:]drawable/drawable_resource"
- android:antialias=["true" | "false"]
- android:dither=["true" | "false"]
- android:filter=["true" | "false"]
- android:gravity=["top" | "bottom" | "left" |
- "right" | "center_vertical" |
- "fill_vertical" | "center_horizontal" |
- "fill_horizontal" | "center" | "fill" |
- "clip_vertical" | "clip_horizontal"]
- android:tileMode=["disabled" | "clamp" |
- "repeat" | "mirror"] />
ここの android:tileMode に repeat を指定すると、android:src で指定した
画像がタイル状になった Bitmap ができます。
この Bitmap をコードから指定するときは
R.drawable.filename
レイアウトXMLの ImageView の android:src や android:backgroundに
指定するときは
@[package:]drawable/filename
とすればOK
こんな感じ

res/drawable/tilebg.xml
- <?xml version="1.0" encoding="utf-8"?>
- <bitmap xmlns:android="http://schemas.android.com/apk/res/android"
- android:src="@drawable/icon"
- android:antialias="true"
- android:dither="false"
- android:filter="false"
- android:gravity="fill"
- android:tileMode="repeat" />
res/layout/main.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="@drawable/tilebg"
- >
- </LinearLayout>
0 件のコメント:
コメントを投稿