20

XMLで幅をハードコーディングせずTextViewに、コンテンツを数行で表示する方法を考えています。

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="right"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="false"
            android:text="Long multiline text"/>

        <TextView
            android:textColor="@color/text_color"
            android:layout_width="130dp"
            android:layout_height="wrap_content"
            />

    </LinearLayout>

どんな考えでも歓迎します。

編集:私の問題は、テキストが設定された幅を超えると(画面の最後に到達するため)、テキストの一部が表示されないことです。テキストが2行に分割されることを期待します

4

4 に答える 4

24

ラッピングされない問題は再現できませんがweight、最初にを使用することで配置の問題を修正できますTextView。次の XML を使用すると、Eclipse のグラフィカル レイアウト ビューで期待どおりの出力が得られます。

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="right"
    android:orientation="horizontal">

    <TextView
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:singleLine="false"
        android:text="Long multiline text"/>

    <TextView
        android:textColor="@color/text_color"
        android:layout_width="130dp"
        android:layout_height="wrap_content"
        />

</LinearLayout>
于 2013-03-06T22:51:11.860 に答える
3

また追加

android:minLines="2"
android:scrollHorizontally="false"
于 2017-07-06T12:30:32.707 に答える