1

ListViewアイテムの背景に問題があります。本来よりも大きいです。これが私の背景リソースです:

ここに画像の説明を入力してください

そして、それは私のデバイスからのスクリーンショットです:

ここに画像の説明を入力してください

レイアウト:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/bg_nocar">
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:layout_marginTop="50dp"
    android:layout_marginLeft="6.67dp">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/reservation"
        android:textStyle="bold"
        style="@style/reservation_text" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/reservation.1"
        style="@style/reservation_text" />
</LinearLayout>
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/reservation.selectclass"
    style="@style/reservation_selectclass_text"
    android:layout_marginTop="33.33dp"
    android:layout_marginLeft="6.67dp" />
<ListView 
    android:id="@id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:divider="#00000000"
    android:dividerHeight="0.67dp" />
</LinearLayout>

これが私のアイテムのレイアウトです。

    <LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/reservation_row"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/car_bg"
android:orientation="horizontal">
    <LinearLayout 
        android:layout_width="93.33dp"
        android:layout_height="98.67dp"
        android:orientation="vertical"
        android:layout_marginLeft="6.67dp"
        android:layout_marginTop="13.33dp">
        <TextView
            android:id="@+id/classname"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            style="@style/reservation_classname" />
        <TextView
            android:id="@+id/name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            style="@style/reservation_name"
            android:layout_marginTop="16.67dp" />
    </LinearLayout>
    <LinearLayout 
        android:layout_width="wrap_content"
        android:layout_height="98.67dp"
        android:orientation="vertical"
        android:layout_marginLeft="6.67dp"
        android:layout_marginTop="13.33dp">
        <ImageView
            android:id="@+id/img"
            android:layout_width="150dp"
            android:layout_height="93.33dp"
            android:layout_marginTop="6dp" />
        <TextView
            android:id="@+id/price"
            android:layout_width="30dp"
            android:layout_height="20dp"/>      
        <TextView
            android:id="@+id/item"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="gone" />
    </LinearLayout>
</LinearLayout>

なぜ背景がこんなに大きいのですか?

4

2 に答える 2

1

画像をリスト項目のサイズに合わせたくないので、背景として配置しないでください。
代わりに、これを行うことができます。背景を白にします (car_bg リソースはすべて白で 1 つのロゴがあるため)。次に、リストビューのレイアウトは次のようになります。

<RelativeLayout>  //background white
  <ImageView>  //Your car_bg with width and height set as wrap_content
  <LinearLayout>  //All the content that you previously had
</RelativeLayout>  

この方法では、画像は拡大縮小されず、元の画像のままになります。とはいえ、画面サイズの異なる車を自分で持っていく必要があります。リソースに使用できるさまざまな密度の画像が必要car_bgです。

于 2012-05-04T19:21:12.650 に答える
0

高さ/幅を手動で設定するのではなく、アスペクト比を維持するようにスケーリングしImageViewてみてください。ImageViewこれが、あなたが引き伸ばされているように見える理由である可能性が最も高いです。

于 2012-05-04T19:13:21.420 に答える