1
[short text][image1][image2]____________________________________

[this is a reallyyyyyyy.............y long text][image1][image2]

私は 3 つのビューを持っています: 可変サイズの 1 つの TextView と 2 つの小さな画像 (16 dp x 16 dp) で、画像が常に 16 dp x 16 dp として表示され、テキストが残りのスペースに表示され、長すぎる場合は省略されるようにレイアウトを実現したいと考えています。3 つのビューのグループはすべて左揃えで、互いに隣り合っている必要があります。

試みたアプローチ:

  1. 重みのない LinearLayout

    欠点: TextView が大きい場合、ImageView は表示されません。

  2. 重み付き LinearLayout

    欠点: ImageView は互いに隣接しなくなりましたが、重みの比率でスペースを占有します。

  3. RelativeLayout - image2: alignParentBottom、image1: toLeftOf="image2"、テキスト: toLeftOf="image1"

    欠点: すべての要素が右揃えになりました。

    _ _ _ _ _ _ _ _ _ _ ____ [短いテキスト][画像1][画像2 ]

このようなレイアウトはどのように実現できますか? できればネストなしですか?

前もって感謝します!

4

2 に答える 2

1

3番目のアプローチを使用する必要がありますが、テキストビューの重力を左に設定してください。

このようなもの:

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:gravity="right"
        android:layout_toLeftOf="@+id/imageView1"
        android:text="TextView" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="16dp"
        android:layout_height="16dp"
        android:layout_toLeftOf="@+id/imageView2"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="16dp"
        android:layout_height="16dp"
        android:layout_alignParentRight="true"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

テキストビューを1行だけに保ちたい場合は、使用しますandroid:singleLine="true"

于 2013-10-26T17:44:33.127 に答える
0

このトリックは私にとってはうまくいきました。これが役立つ場合は、これを試してください。

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

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:paddingRight="32dp"
    android:singleLine="true"
    android:text="This is a very large text just to test the alignment of the images with the textview" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="16dp"
    android:layout_height="16dp"
    android:layout_alignRight="@+id/textView1"
    android:src="@drawable/ic_launcher" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="16dp"
    android:layout_height="16dp"
    android:layout_toLeftOf="@+id/imageView2"
    android:src="@drawable/ic_launcher" />
</RelativeLayout>
于 2014-10-10T06:41:57.287 に答える