Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.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
Android 在列表视图前浮动一个按钮_Android_Android Layout_Android Listview_Android View_Android Button - Fatal编程技术网

Android 在列表视图前浮动一个按钮

Android 在列表视图前浮动一个按钮,android,android-layout,android-listview,android-view,android-button,Android,Android Layout,Android Listview,Android View,Android Button,我希望有一个按钮永久浮动在一个片段中的可滚动列表视图的顶部。我尝试过使用框架布局、线性布局、RelativeLayout等,但没有任何效果 以下是我的基本代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_p

我希望有一个按钮永久浮动在一个片段中的可滚动列表视图的顶部。我尝试过使用框架布局、线性布局、RelativeLayout等,但没有任何效果

以下是我的基本代码:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!--        New Project Button-->
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_margin="5dp"
    android:id="@+id/fragment_profile_project_relLayoutButton">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/fragment_profile_project_newProject_button"
        android:layout_alignParentRight="true"
        android:paddingHorizontal="15dp"
        android:text="@string/project_new_project_button"
        android:background="@drawable/white_rounded_button"/>
</RelativeLayout>

<!--        List View-->
<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/fragment_profile_project_listView"
    android:layout_marginBottom="50dp"/>

Android Studio设计视图“理解”我正在尝试做的事情,但当我运行应用程序时,只会出现“新建项目”按钮,或者什么都没有

有人知道如何在ListView前面设置浮动按钮吗

谢谢


Alex

用按钮将
列表视图
移动到
相对位置上方。布局中的俯视图是布局底部的视图,因此将listview移动到布局文件的顶部将使其成为底部视图

使用按钮将
listview
移动到
RelativeLayout
上方。布局中的俯视图是布局底部的视图,因此将listview移动到布局文件的顶部将使其成为底部视图

Android Studio设计视图“理解”,但当我只运行应用程序时 “新建项目”按钮出现,或不显示任何内容

您可能需要检查列表视图设置的代码

但是,有许多方法可以在
列表视图
上实现
FAB
。最简单的 使用
FrameLayout
如下-

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

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        ..................................../>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_margin="16dp"
        android:layout_gravity="end"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ..................................../>

</FrameLayout>

快乐编码

你说得对

Android Studio设计视图“理解”,但当我只运行应用程序时 “新建项目”按钮出现,或不显示任何内容

您可能需要检查列表视图设置的代码

但是,有许多方法可以在
列表视图
上实现
FAB
。最简单的 使用
FrameLayout
如下-

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

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        ..................................../>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_margin="16dp"
        android:layout_gravity="end"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ..................................../>

</FrameLayout>


快乐编码

仅在列表和浮动按钮内创建带有约束视图组的布局,仅此而已,仅在列表和浮动按钮内创建带有约束视图组的布局