0

それぞれに2つのテキストビューを持つ2つの線形レイアウトを持つ相対レイアウトがあります。テキストビューを横一列に表示したかったのです。コードを以下に示します。

     <RelativeLayout
        android:id="@+id/linear2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <LinearLayout
            android:id="@+id/txtlinear"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/esms_parentfees_classtext"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/esms_parentfees_classdetais"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
      <LinearLayout
            android:layout_gravity="center_horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/esms_parentfees_classdetais"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/esms_parentfees_datetext"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/esms_parentfees_datedetais"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </RelativeLayout>
4

4 に答える 4

1

XML に関する注意事項:

  • LinearLayout 内で toRightOf などを使用することはできません
  • RelativeLayout には向きがありません

これは、何らかの理由ですべての XML を表示するために必要ですか? この行を無視する

<RelativeLayout 
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/esms_parentfees_classtext"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.5" />

        <TextView
            android:id="@+id/esms_parentfees_classdetais"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.5" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/esms_parentfees_datetext"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.5" />

        <TextView
            android:id="@+id/esms_parentfees_datedetais"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.5" />
    </LinearLayout>

</RelativeLayout>
于 2012-11-20T14:55:24.737 に答える
0

4 つのテキストビューが連続して必要な場合は、相対レイアウトで 2 つのリニア レイアウトを使用する代わりに、4 つのテキスト ビューを含むリニア レイアウト (またはテーブル レイアウト) を使用するのが簡単です。

これを見てください:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/txtlinear"
    >
   <TextView
        android:id="@+id/esms_parentfees_classtext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="hi" />

    <TextView
        android:id="@+id/esms_parentfees_classdetais"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="hi" />

    <TextView
        android:id="@+id/esms_parentfees_datetext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="hi" />

    <TextView
        android:id="@+id/esms_parentfees_datedetais"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="hi" />


</LinearLayout>

また

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/txtlinear"
 >

<TableRow
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/esms_parentfees_classtext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="hi" />

    <TextView
        android:id="@+id/esms_parentfees_classdetais"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="hi" />

    <TextView
        android:id="@+id/esms_parentfees_datetext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="hi" />

    <TextView
        android:id="@+id/esms_parentfees_datedetais"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="hi" />
</TableRow>

</TableLayout>

または、2 つの線形レイアウトを含む相対レイアウトが必要な場合は、上記の解決策のいずれかに従うことができます

于 2012-11-20T15:15:18.203 に答える
0

最も簡単な方法は、外側の RelativeLayout を LinearLayout にすることです

 <LinearLayout
    android:id="@+id/linear2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

次に、次のようなタグを削除します

android:layout_toRightOf="@+id/esms_parentfees_classdetais"

または、上記のタグを次のように変更することもできます

android:layout_below="@+id/esms_parentfees_classdetais"
于 2012-11-20T14:52:40.723 に答える
-1
<RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            >
            <TextView
                 android:id="@+id/esms_parentfees_classtext"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />
            <TextView
                 android:id="@+id/esms_parentfees_classdetais"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toLeftOf="@+id/esms_parentfees_classtext"
                 />
        </RelativeLayout>
于 2012-11-20T14:57:06.483 に答える