2

背景画像を RelativeLayout に配置したい。背景画像には、椅子、テーブル、カードなどのオブジェクトが含まれています。

android:background="@drawable/remy_menu_background"しかし、いまいましいものは画面に従って伸び、カードとテーブルは引き伸ばされているように見えます。

どの画面でも問題なく表示されるようにするには、どうすればよいですか?

4

3 に答える 3

9

タグを使用するXMLドローアブルを使用して、ストレッチを無効にすることができます。

<bitmap android:src="@drawable/background" android:gravity="center" />
于 2012-07-12T09:06:39.380 に答える
2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
    android:id="@+id/main_backgroundImage"
    android:layout_width="match_parent" // comment: stretches picture in the width if too small. 
                                           use "wrap_content" does not stretch, but leaves space
    android:layout_height="match_parent" // in my case I always want the height filled
    android:layout_alignParentTop="true"
    android:scaleType="centerCrop" // will crop picture left and right , so it fits in height and keeps aspect ratio
    android:contentDescription="@string/image"
    android:src="@drawable/your_image" />

<LinearLayout
    android:id="@+id/main_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
</LinearLayout>
于 2013-11-29T05:29:24.440 に答える
1

このような状況では .9.png 画像を使用でき、画像のどの領域を伸ばす必要があり、どの領域を伸ばさないかを指定できます。android-sdk 内の「tools」フォルダーにある「draw9patch」ツールを使用して、任意の png を .9.png に変換できます。

于 2012-07-12T09:14:39.387 に答える