Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何结合相对和线性来实现这种XML?_Java_Android_Xml_Android Layout_Android Relativelayout - Fatal编程技术网

Java 如何结合相对和线性来实现这种XML?

Java 如何结合相对和线性来实现这种XML?,java,android,xml,android-layout,android-relativelayout,Java,Android,Xml,Android Layout,Android Relativelayout,我想创建 Layout出现在附加图像中,但我不能,或者它移动或重叠,我不适合完美地播放宽度和高度。我想有一个水平的列表视图,我会把它放在一个线性布局里面,红色是它,橙色是4个矩形(我试着把它变成相对的按钮或图像按钮,我会放进去,但我没能做到 我试着把FrameLayout放进去,在里面我已经可以玩相对的了,但是我总是把自己放在左上角,没有办法将它们向右或向下移动,我希望一切都是方形的。做过类似或类似事情的人 我的代码,但我不能实现我的形象与橙色和红色矩形 <RelativeLayout

我想创建

Layout
出现在附加图像中,但我不能,或者它移动或重叠,我不适合完美地播放宽度和高度。我想有一个水平的
列表视图
,我会把它放在一个
线性布局
里面,红色是它,橙色是4个矩形(我试着把它变成相对的
按钮或
图像按钮
,我会放进去,但我没能做到

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

我的代码,但我不能实现我的形象与橙色和红色矩形

<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对我来说是不可能的,所以我只能用
相对论将1
线性布局
和1
框架布局
放在
上,但是别担心,现在我用我的代码更新了我的问题…@Rasi我已经更新了我的代码,请帮我解决我的问题你已经放了1背景带有
笔划
但是如果我想在所有4个imagebutton的背景中使用1种不同的颜色,我可以用不同的背景颜色放置4个
borders.xml
吗?是的,你可以…你必须更改笔划颜色,并为每个imagebutton应用不同的背景绘制。一个问题,如果我想在listview的顶部添加一个textview,只能我把textView放在上面,但我不能这样做..t.t你可以在上面添加textView只需将第一个Linearlayout方向更改为垂直
android:orientation=“vertical”
…然后添加textView好的,太好了!谢谢你,你就是最好的哈哈:)
<?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>
<