次のようなテキストの行を取得しようとしています
foofoofoo-barbarbar
ただし、1行に収まらない場合は、fooとbarを省略してください。つまり、私はそれらを短縮しようとしています。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/text_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="0dip"
android:layout_weight="1"
android:textColor="#ffffff"
android:singleLine="true"
android:ellipsize="true"
android:text="foofoofoofoo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:text=" - " />
<TextView
android:id="@+id/text_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="0dip"
android:layout_weight="1"
android:textColor="#ffffff"
android:singleLine="true"
android:ellipsize="true"
android:text="barbarbarbar" />
</LinearLayout>
これは部分的に機能します。
TextView
'slayout_width
をbe0dip
およびlayout_weight
toに設定する1
と、それぞれが使用可能なスペースの50%を占めることになります。
singleLine
totrue
とellipsize
toを設定すると、テキストがコンテナよりも大きい場合、それらはfoofootrue
のように見えます。
したがって、私の結果(テキストが長い場合)は
foofoo..-バーバー..
どっちだ!したがって、これは機能します。
今、私が修正しようとしているのは、最初のTextView
(id:text_1)がによって与えられた50%未満のテキストを持っていて、layout_width="0dip"
それlayout_weight="1"
を望んでいる場合wrap_content
です。それ以外の場合は、次のようになります。
foo 空白スペース -バーバー。
そして私は欲しい
foo-バーバーバー
これが私が変更layout_width="wrap_content"
して追加した理由ですandroid:maxWidth="0dip"
が、これは機能しません!私が言っていることを無視しwrap_content
、それでもこの見解を50%与えているようです!
android:adjustViewBounds="true"
動作させるには追加する必要があると読みmaxWidth
ましたが、これによる影響はありませんでした。