gpt4 book ai didi

android - 无法设置 ListView

转载 作者:行者123 更新时间:2023-11-30 02:31:17 25 4
gpt4 key购买 nike

这是我的 xml 代码。我想将按钮上方和线性布局名称下方的 ListView 设置为“titlpricelinearlayout”。但我无法做到这一点。我放置在按钮上方但不在该线性布局下方。这是我想要的图片

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

<LinearLayout
android:id="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/body_background"
android:orientation="vertical" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="35dp"
android:text="CURRENT ORDER"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />

<LinearLayout
android:id="@+id/titlpricelinearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="20dp" >

<TextView
android:id="@+id/recipetitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Your recipes"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />

<LinearLayout
android:id="@+id/linearprice"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal" >

<TextView
android:id="@+id/txt_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:paddingRight="10dp"
android:text="-price"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

<ListView
android:id="@+id/recipeslist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/buttonorder"
android:layout_alignParentLeft="true" >
</ListView>

<Button
android:id="@+id/buttonorder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/footer"
android:background="@drawable/red_button"
android:text="ORDER"
android:textColor="#FFFFFF" />

<LinearLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >

<include layout="@layout/tabbar" />
</LinearLayout>

<LinearLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical" >

<include layout="@layout/header" />
</LinearLayout>

</RelativeLayout>

最佳答案

使用 LinearLayout 作为父级而不是 Relativelayout 并将 weight 属性赋予 ListView,这样它将占据屏幕上的剩余高度:

<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:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<include layout="@layout/header" />
</LinearLayout>

<LinearLayout
android:id="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/body_background"
android:orientation="vertical" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="35dp"
android:text="CURRENT ORDER"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />

<LinearLayout
android:id="@+id/titlpricelinearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="20dp" >

<TextView
android:id="@+id/recipetitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Your recipes"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />

<LinearLayout
android:id="@+id/linearprice"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal" >

<TextView
android:id="@+id/txt_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:paddingRight="10dp"
android:text="-price"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

<ListView
android:id="@+id/recipeslist"
android:layout_width="match_parent"
android:layout_height="0d"
android:layout_weight="1"/>

<Button
android:id="@+id/buttonorder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/red_button"
android:text="ORDER"
android:textColor="#FFFFFF" />

<LinearLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<include layout="@layout/tabbar" />
</LinearLayout>

</LinearLayout>

关于android - 无法设置 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27309557/

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