我怎样才能结合相对和线性来实现这个XML?

How can I combine Relative and Linear to achieve this XML?

我想创建

Layout 出现在附图中,但我做不到,或者它移动或者我重叠,我不适合完美地玩宽度和高度。我想要一个水平的 listview,我会把它放在一个 LinerLayout 里面,它是红色的,4 个橙色的矩形(我试过 Relative 会是我将放入其中的按钮或 imagebutton,但我无法做到。

我试过把FrameLayout放在里面,我已经可以用Relative玩多一点了,但我总是把自己放在左上角,没办法移动它们向右或向下,我希望一切都是正方形的。有人做过类似或相似的事情吗?

我的代码,但我无法用橙色和红色矩形实现我的图像。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:stretchColumns="1">


<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="111dp"
        android:orientation="horizontal"></LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="173dp">

    </RelativeLayout>
</FrameLayout>
</RelativeLayout>

将相对布局设为父级。

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

  <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation=horizontal"
    android:alignParentTop=""
    android:id="llTopH".....>
       <your code for top layout>
  </LinearLayout>


  <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation=horizontal"
    android:layout_below="llTopH"
    android:weightSum = "2"
    android:id="llTopH2".....>

     <LineraLayout
        android:layout_width="0dp"
       android:weight = "1"
    android:layout_height="wrap_content"
      />

  <LineraLayout
        android:layout_width="0dp"
       android:weight = "1"
    android:layout_height="wrap_content"
      />

this will two layouts on 2nd line

 </LinearLayout>

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation=horizontal"
    android:layout_below="llTopH2"
    android:weightSum = "2"
    android:id="llTopH3".....>

      <LineraLayout
        android:layout_width="0dp"
       android:weight = "1"
    android:layout_height="wrap_content"
      />

      <LineraLayout
        android:layout_width="0dp"
       android:weight = "1"
    android:layout_height="wrap_content"
      />

this will two layouts on 3rd line

 </LinearLayout>

</RelativeLayout>     

试试这个布局:

 <?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"
    android:padding="5dp"
    android:weightSum="5">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@drawable/border"
        android:orientation="horizontal">

        <ListView
            android:id="@+id/list_item"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"></ListView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="4"
        android:orientation="vertical">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2"
            android:orientation="horizontal"
            android:weightSum="2">


            <ImageButton
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/border"
                android:src="@mipmap/ic_launcher" />

            <ImageButton
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/border"
                android:src="@mipmap/ic_launcher" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2"
            android:orientation="horizontal"
            android:weightSum="2">


            <ImageButton
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/border"
                android:src="@mipmap/ic_launcher" />

            <ImageButton
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="@drawable/border"
                android:src="@mipmap/ic_launcher" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

在 res/drawable/border.xml

 <?xml version="1.0" encoding="utf-8"?><!--  res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:padding="10dp"
    android:shape="rectangle">

    <stroke
        android:width="3dp"
        android:color="#000000" />

    <corners android:radius="0dp" />
</shape>

输出

<?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="match_parent"
      android:layout_height="0dp"
      android:layout_weight="1"
      android:orientation="horizontal">

    <ListView
        android:id="@+id/listview"
        android:rotation="-90"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </ListView>
  </LinearLayout>

  <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="0dp"
      android:layout_weight="4"
      android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:orientation="horizontal"
        android:weightSum="2">


      <ImageButton
          android:layout_width="0dp"
          android:layout_height="match_parent"
          android:layout_weight="1"
          android:src="@mipmap/ic_launcher" />

      <ImageButton
          android:layout_width="0dp"
          android:layout_height="match_parent"
          android:layout_weight="1"

          android:src="@mipmap/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:orientation="horizontal"
        android:weightSum="2">


      <ImageButton
          android:layout_width="0dp"
          android:layout_height="match_parent"
          android:layout_weight="1"
          android:src="@mipmap/ic_launcher" />

      <ImageButton
          android:layout_width="0dp"
          android:layout_height="match_parent"
          android:layout_weight="1"
          android:src="@mipmap/ic_launcher" />
    </LinearLayout>
  </LinearLayout>
<