Android—在XML布局中构建视图表的最佳实践

Android—在XML布局中构建视图表的最佳实践,android,android-layout,android-linearlayout,android-xml,android-tablelayout,Android,Android Layout,Android Linearlayout,Android Xml,Android Tablelayout,我正在尝试建立一个视图表,它将匹配屏幕的高度和宽度。 视图之间的间距应随着屏幕的增大而增大。 我试着用重量来控制,但重量控制宽度或高度,而不是同时控制两者。嵌套权重对性能不利。。 这就是我或多或少想要达到的目标- 这就是我迄今为止所尝试的: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" andr

我正在尝试建立一个视图表,它将匹配屏幕的高度和宽度。 视图之间的间距应随着屏幕的增大而增大。 我试着用重量来控制,但重量控制宽度或高度,而不是同时控制两者。嵌套权重对性能不利。。 这就是我或多或少想要达到的目标-

这就是我迄今为止所尝试的:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context=".SomeActivity" >

<View
  android:id="@+id/content"
  .../>

<LinearLayout
    android:id="@+id/table"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/content2"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/content"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="30dp"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/firstRow"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="8dp"
            android:background="@drawable/memory_card_back"
            android:gravity="center"
            android:textSize="16sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="8dp"
            android:background="@drawable/memory_card_back"
            android:gravity="center"
            android:textSize="16sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="8dp"
            android:background="@drawable/memory_card_back"
            android:gravity="center"
            android:textSize="16sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="8dp"
            android:background="@drawable/memory_card_back"
            android:gravity="center"
            android:textSize="16sp" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/secondRow"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="10dp"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="8dp"
            android:background="@drawable/memory_card_back"
            android:gravity="center"
            android:textSize="16sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="8dp"
            android:background="@drawable/memory_card_back"
            android:gravity="center"
            android:textSize="16sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="8dp"
            android:background="@drawable/memory_card_back"
            android:gravity="center"
            android:textSize="16sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="8dp"
            android:background="@drawable/memory_card_back"
            android:gravity="center"
            android:textSize="16sp" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/thirdRow"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="10dp"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="8dp"
            android:background="@drawable/memory_card_back"
            android:gravity="center"
            android:textSize="16sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="8dp"
            android:background="@drawable/memory_card_back"
            android:gravity="center"
            android:textSize="16sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="8dp"
            android:background="@drawable/memory_card_back"
            android:gravity="center"
            android:textSize="16sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="8dp"
            android:background="@drawable/memory_card_back"
            android:gravity="center"
            android:textSize="16sp" />
    </LinearLayout>

</LinearLayout>
<View
 android:id="@+id/content2" />
我在垂直线性布局中使用了3个内部水平线性布局。3个水平铺层布局中的每一个都具有布局权重

如果我忘了提什么,请告诉我。
谢谢。

看来你在找一个GridView……没有回收的时候,它不是腰围吗?视图不会改变或移动。。我在问,我真的不知道,因为我从未使用过GridView。不,这不是浪费。它肯定比嵌套布局更有效,特别是在使用嵌套权重的情况下!。好啊谢谢,我试试看,很简单。与ListView差不多。