0

レイアウトの上部に2つのTextViewがあり、下部にImageViewがあるレイアウトを作成しようとしています。しかし、ImageViewのscaledingtypに問題があります。画像は常にプロポーショナルにサイズ変更する必要がありますが、常に中央の下部に配置する必要があります。これが私の問題の写真です:

レイアウト

私の問題を理解していただければ幸いです。
これが私のコードです:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent"
android:orientation="vertical" >

<TextView
    android:id="@+id/textViewGameOver1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_gravity="top|center_horizontal"
    android:gravity="center"
    android:text="TextView1"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textViewGameOver2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textViewGameOver1"
    android:layout_centerHorizontal="true"
    android:layout_gravity="top|center_horizontal"
    android:gravity="center"
    android:text="TextView2"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
    android:id="@+id/imageViewGameOver"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_below="@+id/textViewGameOver2"
    android:layout_centerHorizontal="true"
    android:layout_gravity="bottom|center_horizontal"
    android:scaleType="fitEnd"
    android:src="@drawable/sheldon_win" />

</RelativeLayout>

この問題を解決するアイデアはありますか?

よろしくお願いします!

4

1 に答える 1

1

RelativeLayoutの代わりにを使用する必要がありますLinearLayout。これにより、画像を希望の場所に配置でき、のサイズをImageView任意のサイズに設定できます。

<ImageView
    android:id="@+id/imageViewGameOver"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:src="@drawable/sheldon_win" />

これにより、画像が右下隅に配置され、画像は画像ファイルのサイズに関係なく配置されます。これを変更したい場合は、幅と高さをdpのサイズに設定できます。

于 2012-09-19T17:53:49.927 に答える