gpt4 book ai didi

java - 我如何结合 Relative 和 Linear 来实现这个 XML?

转载 作者:行者123 更新时间:2023-11-30 00:38:18 25 4
gpt4 key购买 nike

我想创建

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

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

enter image description here

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

<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>

最佳答案

试试这个布局:

 <?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>

输出

enter image description here

关于java - 我如何结合 Relative 和 Linear 来实现这个 XML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43032775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com