そのためのxmlレイアウトはないと思います。私の推測では、内部のテキストの長さを拡張TextView
して測定し、onDraw(...)
それに応じてテキストを調整する必要があると思います (つまり、テキストがキャンバスに収まるまで一度に 1 文字ずつ削除します)。
あなたと非常によく似た別の質問を見つけました: TextView のセクションのみを省略します。真ん中の楕円形以外の答えはありません。
別の考え:
メインテキスト(ellipsize left、wrap_content)を含む1つのテキストビューと、括弧内に数字(wrap_content)を含む別のテキストビューを、両方とも水平線形レイアウト内に配置するとうまくいくかどうか疑問に思っています。そのレイアウトは、相対レイアウトとボタンのlayout_toLeftOf内にあり、これはwrap_content、layout_alignParentRightになります。
意味はありますか?私は今、自分でテストするための Eclipse を持っていません。(n) textview がボタンの後ろで失われるかどうか、または長いテキストで失われるかどうかはわかりません。
別の方法として (あまり面白くありません)、すべて layout_toRightOfの 2 つのテキストビューと右に配置されたボタン ( layout_alignParentRight ) を使用して1 つの相対レイアウトを設定し、最初のテキストビュー ( android:maxWidth ) の最大幅を設定できます。ただし、画面ごとに異なるレイアウトを設定する必要があります。
必要に応じて機能する固定最大幅の例:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click me"
android:id="@+id/bt1"
android:layout_alignParentRight="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="short text"
android:lines="1"
android:ellipsize="end"
android:id="@+id/t1"
android:layout_alignParentLeft="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(n)"
android:lines="1"
android:id="@+id/n1"
android:layout_toRightOf="@id/t1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="click me"
android:id="@+id/bt2"
android:layout_below="@id/bt1"
android:layout_alignParentRight="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="very long text that will not fit in any layout, regardless of the size of the screen"
android:lines="1"
android:ellipsize="end"
android:id="@+id/t2"
android:layout_below="@id/bt1"
android:layout_alignParentLeft="true"
android:maxWidth="220dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="(n)"
android:lines="1"
android:id="@+id/n2"
android:layout_below="@id/bt1"
android:layout_toRightOf="@id/t2"
/>
</RelativeLayout>