私は3つのビューを並べて表示しようとしています:text1 - img - text2。 Imgは常にtext1(余分なスペースなし)で正しくなければなりません。レイアウトの重みを使ってこれを解決しようとしましたが、そのソリューションではimgは常に親ビューの中心にあります。横並びのビュー、動的サイズ
期待される結果:テキスト2長い短い
テキスト1、。テキスト1とIMGとの間に
+----------------------------------------+
| [Text1 a] [img] [Text2 asdfghjklz... ] |
+----------------------------------------+
ellipsized両方のテキストをスペースを追加しないでください、
+----------------------------------------+
| [Text1 asdfg...] [img] [Text2 asdf...] |
+----------------------------------------+
テキスト1長いテキスト2短い
+----------------------------------------+
| [Text1 asdfgadfafs...] [img] [Text2 a] |
+----------------------------------------+
これは私が得ることができる最も近いです(使用してIMGの中心を保ちますweight)であるが、text1が短い場合、imgはまだレイアウトの中心にあるという問題があります。 Imはtext1の右側に常に真っ直ぐにいなければなりません。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textview1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
tools:text="Text1 asdfghjkl" />
<ImageView
android:id="@+id/img"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:src="@drawable/ic_arrow" />
<TextView
android:id="@+id/textview2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
tools:text="Text2 asdfghjkl" />
</LinearLayout>
Text1が長い場合、imgとText2が短い場合はどうすればよいですか? – sJy
例を追加したので、できるだけtext2をプッシュしてください。 – devha