3

私は自分の xml レイアウトに多くの textviews を配置したいのですが、それぞれ 2 つを 1 行に並べます。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

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

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Name: " />

        <TextView
            android:id="@+id/playertvName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/red"
            android:textSize="20dp" />
    </LinearLayout>

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

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Nationality: " />

        <TextView
            android:id="@+id/playertvNationality"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/red"
            android:textSize="20dp" />
    </LinearLayout>

</LinearLayout>

しかし、2つのテキストビューごとに新しいlinearlayoutを作成し続けるのは良い方法ではないようです。別の方法はありますか?ありがとう

4

4 に答える 4

3

試してみてくださいGridLayout。これが公式の Google docで、これがです。

于 2012-12-08T08:34:46.663 に答える
2

あなたがレイアウト(おそらくフォーム)を使用している目的のために、あなたがそれを開発した方法はまったく問題ないと思います。GridViewこの場合、 aまたは anyAdapterViewはあなたの要件に合わないと思います。

LinearLayout適切なウェイトまたは で使用できますRelativeLayout

于 2012-12-08T08:38:13.330 に答える
1

LinearLayout の代替として、TableLayout または GridView を使用できます。

  1. TableLayout を使用すると、テキスト ビューを表形式で配置できます。テキスト ビューの数が非常に少なく固定されている場合は、TableLayout をお勧めします。

  2. GridView を使用すると、コンポーネントを Grid fasion でレイアウトできます。これはアダプタービューです。つまり、GridView によってビューを再利用できます。ある程度複雑になるため、テキストビューの数が多い場合に役立ちます。

于 2012-12-08T08:35:39.503 に答える
0

1 つの相対レイアウトを使用して、android:layout_toLeftOf=""、android:layout_toRightOf="" android:layout_below="" android:layout_above="" で再生します。

于 2012-12-08T08:37:54.690 に答える