gpt4 book ai didi

android - 在 ListView 顶部包含 float 操作按钮

转载 作者:太空宇宙 更新时间:2023-11-03 13:11:41 25 4
gpt4 key购买 nike

我想在我的一个布局中添加一个 float 操作按钮。我为要包含在我的主布局中的 float 操作按钮创建了一个单独的布局。但每当我包含它时,它都不在 ListView 的顶部。

float 操作按钮 XML:

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

<android.support.design.widget.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="23dp"
android:layout_marginEnd="22dp"
android:clickable="true"
app:fabSize="mini"
app:srcCompat="@android:drawable/ic_menu_add" />
</RelativeLayout>

Activity 布局:

<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:orientation="vertical"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:weightSum="1"
android:background="@color/BG_beige">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="44dp"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="10dp">

<TextView
android:id="@+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.58"
android:text="Name"
android:textSize="20sp"/>

<TextView
android:id="@+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Price"
android:textSize="20sp"/>

<TextView
android:id="@+id/textView19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.51"
android:text="Paid"
android:textSize="20sp"
android:gravity="center"/>



</LinearLayout>

<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<include
layout="@layout/utility_fab"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

</LinearLayout>

所以最终的布局是这样的: Main Layout

最佳答案

将您的布局包裹在 FrameLayout 中并应用 android:layout_gravity="bottom"

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<include
layout="@layout/utility_fab"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom" />
</FrameLayout>

关于android - 在 ListView 顶部包含 float 操作按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43961925/

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