EllipsizeなtextView内部にカスタムlistView
質問
いlistViewとカスタムオブジェクト定義のxmlベースのレイアウトします。たいのtextView身分を証明するものの提示が必要"情報"をellipsized一つのラインは、たっての属性
android:singleLine="true"
android:ellipsize="end"
せずに成功。
の場を設定しますlayout_width固定幅のような例
android:layout_width="100px"
テキストは切り捨てられます。でも持ち運びに便利なこの理由は受け付けていません。
きスポット問題なのでしょうか。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5px"
>
<TextView
android:id="@+id/destination"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="22dp"
android:paddingLeft="5px"
/>
<TextView
android:id="@+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="15dp"
android:paddingLeft="5px"
/>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/info_table"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="5px"
android:paddingTop="10px"
>
<TableRow>
<TextView
android:id="@+id/driver_label"
android:gravity="right"
android:paddingRight="5px"
android:text="@string/driver_label" />
<TextView
android:id="@+id/driver" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/passenger_label"
android:gravity="right"
android:paddingRight="5px"
android:text="@string/passenger_label" />
<TextView
android:id="@+id/passengers" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/info_label"
android:gravity="right"
android:paddingRight="5px"
android:text="@string/info_label"/>
<TextView
android:id="@+id/info"
android:layout_width="fill_parent"
android:singleLine="true"
android:ellipsize="end" />
</TableRow>
</TableLayout>
解決
省略記号が壊れています(バグレポートに投票 、特に再現できないと主張しているため)、マイナーハックを使用する必要があります。使用:
android:inputType="text"
android:maxLines="1"
楕円化するものすべて。また、 singleLine
は使用しないでください。廃止されました。
更新:
詳しく調べると、問題は、テーブルが画面の右側からはみ出していることです。 TableLayout
の定義を次のように変更します:
<TableLayout
android:id="@+id/info_table"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="5px"
android:paddingTop="10px"
android:shrinkColumns="1">
その問題を修正し、上で言ったことを行って TextView
を省略します。
他のヒント
廃止されたプロパティを使用しなくても、次の行は私にとってはうまく機能します
android:ellipsize="end"
android:lines="1"
android:scrollHorizontally="true"
ref http://code.google.com/p / android / issues / detail?id = 882#c9
また同様の結果としてのSteve:
android:ellipsize="marquee" android:scrollHorizontally="true" android:線="1"
コンビニエンスストアでのお支
試用...
i.e。
android:ellipsize="marquee"
android:focusable="true" android:marqueeRepeatLimit="num|marquee_forever"
android:lines="1" android:focusableInTouchMode="true"
android:scrollHorizontally="true"
マーキーは、 http://code.google.com/p/android/issues/detail?id=5364
これら3つの問題(クローズ&再オープン)と以前の投稿をチェックした後、キーはTextViewを外側のLinearLayout(または使用している他のレイアウト)でラップし、&quot; < strong> layout_width &quot; TextViewに含まれるテキストの長さよりも少し小さい外側のレイアウト幅の。 &quot; android:ellipsize&quot;を作成するには、幅を LIMIT する必要があるようです。適切に動作します。
この問題のヒントに従ってください。ハッキング用のこれらすべての属性を追加した後、たとえば、外側のLinearLayoutのlayout_widthを240dpに設定します。
<Linearlayout
android:layout_width="240dp"
android:layout_height="wrap_content"
...>
<TextView
....
android:singleLine="true"
android:lines="1"
android:maxLines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
android:text="this is a text which length should be longer than 240dp"
/>
</LinearLayout>
TextViewの最後に「...」を表示できるようになりましたが、あまり受け入れられませんが、うまくいきます!そして、通常のTextViewで使用してもリストアダプターのTextViewで使用しても動作すると思います。
結果のスクリーンショットです!
これらの3つの問題の参照:
この属性のどこかで見つけた
<TextView ...
android:singleLine="true"
android:ellipsize="marquee" />
私にとっては問題なく動作します(Android 1.5)
私にとって、これらの属性は機能しました。 API 8以降でテストしました
XMLで
<TextView
....
android:maxLines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
....
/>
プログラムで
setMaxLines(1);
setEllipsize(TruncateAt.END);
setHorizontallyScrolling(true);
作成したカスタムViewGroup内にTextViewを配置する場合、測定後に寸法を変更した場合は、必ず再度測定してください。
たとえば、onLayoutで新しいディメンションを計算しました。 child.layoutを呼び出す前に、呼び出します
measureChild(child,
View.MeasureSpec.makeMeasureSpec(childWidth, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(childHeight, View.MeasureSpec.EXACTLY));
リサイクラービューカードでも同じ問題が発生しました。次のコードを追加することでこれを解決しました。
<TextView
android:ellipsize="end"
android:maxLines="1"/>