4

リスト項目として使用ImageViewするTextView内にとを入れて、を の行番号で縦に伸ばしたい。のdrawableは縦棒のpng画像です。RelativeLayoutImageViewTextViewImageView

次のレイアウトでは、Eclipse の Layout ビューでは問題ないように見えますが、実行時にImageViewの高さが満たされません。RelativeView代わりに、常に元の画像の高さを維持します。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent" >
   <ImageView android:id="@+id/iv"
       android:layout_width="wrap_content"
       android:layout_height="fill_parent"
       android:layout_alignParentLeft="true"
       android:src="@drawable/vbar"
       android:adjustViewBounds="false"
       android:scaleType="fitXY"/>
   <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:singleLine="false"
       android:layout_toRightOf="@id/iv"
       android:layout_alignParentBottom="true" />
</RelativeLayout>

期待どおりに(または Eclipse レイアウト ビューに示されているように)動作しないのはなぜですか?

4

2 に答える 2

1

私はあなたのコードにいくつかの変更を加えました。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:singleLine="false"
        android:text="@string/text" />

    <ImageView
        android:id="@+id/iv"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_above="@id/tv"
        android:adjustViewBounds="false"
        android:scaleType="fitXY" />

</RelativeLayout>

現在、適切な出力が得られています。私がしたことは、最初にテキストビューを宣言し、それを親の下部に揃えることです。次に、imageview を宣言し、textview の一番上に配置しました。そのため、imageview は textview のすぐ上から開始され、残りのすべての高さが取得されます。複数行のテキストビューもテストしました。それが役に立てば幸い。

于 2013-01-08T11:59:17.807 に答える
-1

私はいくつかのことをします:

  1. TextView を「drawableLeft」と組み合わせて、レイアウトを簡素化します。
  2. 画像を 9 パッチ画像にして、それに応じて拡大します。
于 2012-04-30T15:44:11.390 に答える