私は2つのテキストビューでリストビューを実装しており、参考のために基本的なレイアウトとフォーマットを使用しています
短い銘柄名の代わりに長いテキストを使用しているため、長いテキストを使用すると 2 番目の .
2つのテキストビューが互いに重ならないようにするにはどうすればよいですか。
私は2つのテキストビューでリストビューを実装しており、参考のために基本的なレイアウトとフォーマットを使用しています
短い銘柄名の代わりに長いテキストを使用しているため、長いテキストを使用すると 2 番目の .
2つのテキストビューが互いに重ならないようにするにはどうすればよいですか。
次のコードを使用して、問題を解決できます。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:id="@+id/ticker_symbol"
android:text="sdasd sadas"
android:layout_weight=".5"/>
<TextView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:id="@+id/ticker_price"
android:text="dfsd"
android:layout_weight=".5"
android:gravity="right" />
</LinearLayout>
出力:
テキストの長さが長いため、次の行または次のTextViewに移動するという意味だと思います
したがって、textViewプロパティandroid:ellipsized = "end"を使用し、代わりにandroid:single_line = "true"を使用することをお勧めします。これは、maxline = 1を直接指定できます。名前のスペルが正しいかどうかわからないため、入力時に確認してください。
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/ticker_symbol"
android:ellipsezed="end"
android:singe_line="true"
android:layout_alignParentLeft="true" />
この説明があなたのためにうまくいくことを願っています。
重複を避けるために、2 番目のテキストビューを右揃えに設定できます (android:layout_toRightOf)。
例えば:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/ticker_symbol"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/ticker_price"
android:layout_toRightOf="@id/ticker_symbol"
android:layout_alignParentRight="true" />
</RelativeLayout>