9

背景がいっぱいになるまで、背景に画像を並べて表示しようとしています。

私の現在のコードは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/cartoonclouds"
    android:contentDescription="@string/desc"
    android:tileMode="repeat" />
  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="@string/hello" />
  </LinearLayout>
</RelativeLayout>

ただし、これにより、画像が下から上に (タイル化されず) カバーされるだけで、左から右にはなりません。私は何をすべきですか?

編集:XMLバージョンを試みました:

<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:tileMode="repeat"
    android:src="@drawable/cartoonclouds" />

main.xml は、その XML ファイルと同じフォルダーで cartoonclouds を見つけることができましたが、その XML ファイルを見つけることができませんでした。

4

1 に答える 1

36

まず、画像をres / drawable/cloud.pngなどのファイルに配置します。これにより、アプリは@ drawable/cloudとしてアクセスできるようになります。しかし、それは(まだ)タイル化されていません。

次に、android:tileMode = "repeat"を使用してビットマップresource(1)を定義する必要があります。たとえば、mytileablebitmap.xmlで定義できます。

<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:tileMode="repeat" 
android:src="@drawable/cloud"/>

これは、元のタイル画像(ドローアブル/クラウド)を参照し、使用可能なスペースを埋めるために自分自身をタイリングする方法を知っているドローアブルを作成しています。

次に、タイル状の背景を使用する場合は、「@ drawable/mytileablebitmap」を使用します。

(1):http ://developer.android.com/guide/topics/resources/drawable-resource.html

于 2012-01-17T18:45:48.943 に答える