gpt4 book ai didi

android - NestedScrollView 将高度设置为两个布局之间的空间

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

我试图将后退按钮保留在页面底部,并让嵌套 ScrollView 填充页面底部统计信息相对布局和后退按钮下方的空间。它目前适合顶部的统计信息,但由于它适合页面,所以将后退按钮推离了页面底部。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.swapsy.jack.broketoballing.FoodActivity"
android:orientation="vertical"
android:id="@+id/linWholePage">

<RelativeLayout
android:id="@+id/statsTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/textbackground"
android:layout_alignParentStart="true"
android:layout_marginBottom="5dp"
android:paddingBottom="5dp">

<ImageView
android:id="@+id/imgFood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_food"
android:layout_marginTop="5dp"
android:layout_marginStart="5dp" android:contentDescription="@string/todo" />

<TextView
android:id="@+id/txtFood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imgFood"
android:layout_marginStart="16dp"
android:layout_toEndOf="@+id/imgFood"
android:text="@string/_300_300"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginTop="5dp"/>

<ProgressBar
android:id="@+id/foodBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/txtFood"
android:layout_marginStart="11dp"
android:layout_toEndOf="@+id/txtFood"
android:layout_marginTop="3dp"
android:background="@drawable/foodbaroutline"
android:max="300"
android:progress="150"
android:progressDrawable="@drawable/foodprogressdrawable"
android:padding="2dp"/>

<ImageView
android:id="@+id/imgHealth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/imgFood"
android:layout_below="@+id/imgFood"
android:src="@drawable/ic_health"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" android:contentDescription="@string/todo" />

<TextView
android:id="@+id/txtHealth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/txtFood"
android:layout_alignTop="@+id/imgHealth"
android:text="@string/_300_300"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginTop="5dp"/>

<ProgressBar
android:id="@+id/healthBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/foodBar"
android:layout_alignTop="@+id/txtHealth"
android:layout_marginTop="3dp"
android:background="@drawable/healthbaroutline"
android:max="300"
android:progress="300"
android:progressDrawable="@drawable/healthprogressdrawable"
android:padding="2dp"/>

<ImageView
android:id="@+id/imgClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/imgHealth"
android:layout_below="@+id/imgHealth"
android:contentDescription="@string/todo"
android:paddingTop="7dp"
android:src="@drawable/ic_clock" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imgClock"
android:layout_marginStart="13dp"
android:layout_toEndOf="@+id/imgClock"
android:text="@string/timestring"
android:textStyle="bold"
android:textSize="17sp"
android:layout_marginTop="12dp"
android:id="@+id/txtTime" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/imgClock"
android:layout_below="@+id/imgClock"
android:src="@drawable/ic_money"
android:layout_marginTop="7dp"
android:id="@+id/imgMoney" android:contentDescription="@string/todo" />

<TextView
android:id="@+id/txtMoney"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imgMoney"
android:layout_alignStart="@+id/txtTime"
android:text="@string/_0"
android:textSize="17sp"
android:layout_marginBottom="5dp"
android:textStyle="bold" />

<ImageView
android:id="@+id/imgBank"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/imgMoney"
android:layout_below="@+id/imgMoney"
android:layout_marginTop="11dp"
android:src="@drawable/ic_bank" />

<TextView
android:id="@+id/txtBankBal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/txtMoney"
android:layout_alignTop="@+id/imgBank"
android:text="$0"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginTop="5dp"/>

</RelativeLayout>

<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@+id/imgBank"
android:layout_marginTop="2dp"
android:layout_marginBottom="3dp"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/5224354917"
android:visibility="visible"
/>


<android.support.v4.widget.NestedScrollView
android:id="@+id/scrFood"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<Button
android:id="@+id/btnEatRubbish"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eat out of a bin $0"
android:textAllCaps="false"
android:textSize="20sp"
android:textStyle="normal" />

<Button
android:id="@+id/btnEatBeans"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eat Beans $2"
android:textAllCaps="false"
android:textSize="20sp"
android:textStyle="normal" />

<Button
android:id="@+id/btnEatSliceOfCake"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eat Slice of Cake $5"
android:textAllCaps="false"
android:textSize="20sp"
android:textStyle="normal" />

<Button
android:id="@+id/btnEatCheeseBurger"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eat Cheese Burger $20"
android:textAllCaps="false"
android:textSize="20sp"
android:textStyle="normal" />

<Button
android:id="@+id/btnEatOrganicMeal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eat Organic Meal $70"
android:textAllCaps="false"
android:textSize="20sp"
android:textStyle="normal" />

<Button
android:id="@+id/btnEatRestaurant"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eat at Restaurant $140"
android:textAllCaps="false"
android:textSize="20sp"
android:textStyle="normal" />

<Button
android:id="@+id/btnEatUltimateMeal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eat an Ultimate Meal $200"
android:textAllCaps="false"
android:textSize="20sp"
android:textStyle="normal" />

</LinearLayout>

</android.support.v4.widget.NestedScrollView>


<RelativeLayout
android:id="@+id/relBack"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|bottom">

<Button
android:id="@+id/btnBack"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:text="@string/back"
android:textAllCaps="false"
android:textSize="20sp"
android:textStyle="normal" />

</RelativeLayout>


</LinearLayout>

我希望它看起来像这样......

The look I want

最佳答案

  • 将您的 nestedScrollView 包含在线性布局中,参数为 as

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

  • 将后退按钮的父级更改为线性布局而不是相对布局,并将其高度参数更改为 wrap_content

代码是这样的:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linWholePage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.swapsy.jack.broketoballing.FoodActivity">

<RelativeLayout
android:id="@+id/statsTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="14dp"
android:background="@drawable/textbackground"
android:paddingBottom="5dp">

<ImageView
android:id="@+id/imgFood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
android:contentDescription="@string/todo"
android:src="@drawable/ic_food" />

<TextView
android:id="@+id/txtFood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imgFood"
android:layout_marginStart="16dp"
android:layout_marginTop="5dp"
android:layout_toEndOf="@+id/imgFood"
android:text="@string/_300_300"
android:textSize="17sp"
android:textStyle="bold" />

<ProgressBar
android:id="@+id/foodBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/txtFood"
android:layout_marginStart="11dp"
android:layout_marginTop="3dp"
android:layout_toEndOf="@+id/txtFood"
android:background="@drawable/foodbaroutline"
android:max="300"
android:padding="2dp"
android:progress="150"
android:progressDrawable="@drawable/foodprogressdrawable" />

<ImageView
android:id="@+id/imgHealth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/imgFood"
android:layout_below="@+id/imgFood"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:contentDescription="@string/todo"
android:src="@drawable/ic_health" />

<TextView
android:id="@+id/txtHealth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/txtFood"
android:layout_alignTop="@+id/imgHealth"
android:layout_marginTop="5dp"
android:text="@string/_300_300"
android:textSize="17sp"
android:textStyle="bold" />

<ProgressBar
android:id="@+id/healthBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/foodBar"
android:layout_alignTop="@+id/txtHealth"
android:layout_marginTop="3dp"
android:background="@drawable/healthbaroutline"
android:max="300"
android:padding="2dp"
android:progress="300"
android:progressDrawable="@drawable/healthprogressdrawable" />

<ImageView
android:id="@+id/imgClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/imgHealth"
android:layout_below="@+id/imgHealth"
android:contentDescription="@string/todo"
android:paddingTop="7dp"
android:src="@drawable/ic_clock" />

<TextView
android:id="@+id/txtTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imgClock"
android:layout_marginStart="13dp"
android:layout_marginTop="12dp"
android:layout_toEndOf="@+id/imgClock"
android:text="@string/timestring"
android:textSize="17sp"
android:textStyle="bold" />

<ImageView
android:id="@+id/imgMoney"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/imgClock"
android:layout_below="@+id/imgClock"
android:layout_marginTop="7dp"
android:contentDescription="@string/todo"
android:src="@drawable/ic_money" />

<TextView
android:id="@+id/txtMoney"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imgMoney"
android:layout_alignStart="@+id/txtTime"
android:layout_marginBottom="5dp"
android:text="@string/_0"
android:textSize="17sp"
android:textStyle="bold" />

<ImageView
android:id="@+id/imgBank"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/imgMoney"
android:layout_below="@+id/imgMoney"
android:layout_marginTop="11dp"
android:src="@drawable/ic_bank" />

<TextView
android:id="@+id/txtBankBal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/txtMoney"
android:layout_alignTop="@+id/imgBank"
android:layout_marginTop="5dp"
android:text="$0"
android:textSize="17sp"
android:textStyle="bold" />

</RelativeLayout>

<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"

android:layout_marginBottom="3dp"
android:layout_marginTop="2dp"
android:visibility="visible"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/5224354917" />

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

<android.support.v4.widget.NestedScrollView
android:id="@+id/scrFood"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<Button
android:id="@+id/btnEatRubbish"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eat out of a bin $0"
android:textAllCaps="false"
android:textSize="20sp"
android:textStyle="normal" />

<Button
android:id="@+id/btnEatBeans"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eat Beans $2"
android:textAllCaps="false"
android:textSize="20sp"
android:textStyle="normal" />

<Button
android:id="@+id/btnEatSliceOfCake"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eat Slice of Cake $5"
android:textAllCaps="false"
android:textSize="20sp"
android:textStyle="normal" />

<Button
android:id="@+id/btnEatCheeseBurger"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eat Cheese Burger $20"
android:textAllCaps="false"
android:textSize="20sp"
android:textStyle="normal" />

<Button
android:id="@+id/btnEatOrganicMeal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eat Organic Meal $70"
android:textAllCaps="false"
android:textSize="20sp"
android:textStyle="normal" />

<Button
android:id="@+id/btnEatRestaurant"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eat at Restaurant $140"
android:textAllCaps="false"
android:textSize="20sp"
android:textStyle="normal" />

<Button
android:id="@+id/btnEatUltimateMeal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Eat an Ultimate Meal $200"
android:textAllCaps="false"
android:textSize="20sp"
android:textStyle="normal" />

</LinearLayout>

</android.support.v4.widget.NestedScrollView>
</LinearLayout>


<LinearLayout
android:id="@+id/relBack"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom">

<Button
android:id="@+id/btnBack"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:layout_marginBottom="5dp"
android:text="@string/back"
android:textAllCaps="false"
android:textSize="20sp"
android:textStyle="normal" />

</LinearLayout>
</LinearLayout>

关于android - NestedScrollView 将高度设置为两个布局之间的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48090494/

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