3

カスタムアダプターを備えた ListView と、このリスト内のアイテムのレイアウトがあります。アイテムのレイアウトは、ImageView を備えた単なる TextView です。画像は画面の右側に配置する必要があります。ただし、TextView 内のテキストの長さによっては、画像の位置が少しずれています。これは次のようになります。

スクリーンショット

これは私のXMLコードです:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:gravity="center_vertical" >

    <TextView
        android:id="@+id/txtCategoryName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="10"
        android:singleLine="true"
        android:ellipsize="end"
        android:gravity="center_vertical"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:textColor="@color/list_text_color"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <ImageView
        android:id="@+id/imgArrowRight"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/right_arrow_44"
        android:contentDescription="@string/img_description_right_arrow"
        android:layout_gravity="right" />

</LinearLayout>

ナッジせずに、画像を常に右に揃えるにはどうすればよいですか?

4

2 に答える 2

9

RelativeLayoutandroid:layout_alignParentRightは、 andを使用して問題をうまく解決するはずandroid:layout_alignParentLeftです。何かのようなもの:

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

<TextView
    android:id="@+id/txtCategoryName"
    android:layout_alignParentLeft="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:ellipsize="end"
    android:gravity="center_vertical"
    android:paddingTop="5dp"
    android:paddingBottom="5dp"
    android:textColor="@color/list_text_color"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
    android:id="@+id/imgArrowRight"
    android:layout_alignParentRight="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/right_arrow_44"
    android:contentDescription="@string/img_description_right_arrow"/>
于 2012-10-28T19:34:15.423 に答える
1

RelativeLayoutを使用し、画像上で親を右に揃え、TextView で親を左に揃えようとしていると思います。

于 2012-10-28T19:30:25.167 に答える