0

4 つの TextView でレイアウトを作成する必要があります。

最初の TextView は画面の左境界に配置され、2 番目の TextView はサイズが異なる場合があり、3 番目の TextView は 2 番目の textView の後に配置され、4 番目の TextView は画面の右境界に配置されます。

2 番目の TextView が短い場合、3 番目の TextView の後に次のような空白が追加されます。

[TextView1 TextView2 TextView3 (free space) TextView4]

2 番目の TextView が長い場合は、最後に ... を付けて省略します。

[TextView1 VeryLooooooongTexVi... TextView3 TextView4]

このレイアウトをxmlで書くにはどうすればよいですか? LinearLayout を使用する必要がありますか、それとも TableLayout の方が優れていますか? 例を挙げていただけますか?

4

2 に答える 2

1

RelativeLayoutを使用して、属性 layout_ alignParentLeft、layout_ alignParentRight、および layout_ toRightOfを使用して、テキストビューを希望どおりに配置できます。2 番目のTextViewは、TextView のmaxWidth、ellipsize、singleLine属性を使用して、必要な方法で設計できます。レイアウトは次のようになります。

     <RelativeLayout android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView android:id="@+id/firstTextView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:text="first"/>

    <TextView android:id="@+id/secondTextView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_toRightOf="@id/firstTextView"
        android:layout_marginLeft="10dp"
        android:singleLine="true"
        android:maxWidth="100dp"
        android:ellipsize="end"
        android:text="secondtextviewlonnnnnnnnnnnnnnnnng"/>

    <TextView android:id="@+id/thirdTextView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_toRightOf="@id/secondTextView"
        android:layout_marginLeft="10dp"
        android:text="third"/>

    <TextView android:id="@+id/fourthTextView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="10dp"
        android:text="fourth"/>

</RelativeLayout>

また、ここでさまざまなレイアウトのサンプル プロジェクトを見つけることができます。

于 2013-01-20T20:36:30.653 に答える
0
<?xml version="1.0" encoding="utf-8"?>

<TextView
    android:layout_width="0"
    android:layout_height="fill_parent"
    android:layout_weight="1" />

<TextView
    android:layout_width="0"
    android:layout_height="fill_parent"
    android:layout_weight="1" />

<TextView
    android:layout_width="0"
    android:layout_height="fill_parent"
    android:layout_weight="1" />


<View
    android:layout_width="0"
    android:layout_height="fill_parent"
    android:layout_weight="1" />

<TextView
    android:layout_width="0"
    android:layout_height="fill_parent"
    android:layout_weight="1" />

于 2013-01-10T16:45:34.137 に答える