gpt4 book ai didi

android - float 操作按钮不显示在 recyclerview 上(位于 DrawerLayout 内)

转载 作者:可可西里 更新时间:2023-11-01 18:47:23 25 4
gpt4 key购买 nike

我正在尝试让 FAB 超过 recyclerview,在我的例子中,它会覆盖整个屏幕。即使 recyclerview 为空,FAB 也不会显示。以下是我的 xml 代码。

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.technistan.ledger.CreateLedger"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"
></include>


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

<android.support.v7.widget.RecyclerView
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:id="@+id/recyclerView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"

/>


<android.support.design.widget.FloatingActionButton
android:id="@+id/myFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="20dp"
app:elevation="4dp" />


</FrameLayout>

</LinearLayout>


<fragment
android:id="@+id/fragment_navigation_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer"
android:name="com.technistan.ledger.NavigationDrawerFragment"
tools:layout="@layout/fragment_navigation_drawer" />


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

预览显示 float 按钮正常,如下图所示; https://www.dropbox.com/s/18u5pt5v6kkkibj/Screen%20Shot%202015-09-13%20at%201.19.20%20PM.png?dl=0

但是当我运行该应用程序时,没有显示 FAB。我尝试了很多组合,但都没有成功。我在没有抽屉导航的情况下在 ListView 上尝试了这个(简单的 Activity ,它在那里工作,即显示在 ListView 上)。

任何帮助将不胜感激。谢谢

[编辑:] 我认为问题是因为父布局,即 android.support.v4.widget.DrawerLayout,我已经将代码从开始复制粘贴到另一个空 Activity ,它在那里显示 float 按钮。但仍然无法弄清楚如何解决这个问题,我需要在 Drawerlayout 中显示 float 操作按钮。

最佳答案

像这样尝试:

删除所有布局。

只保留一个父级,即 CoordinatorLayout

CoordinatorLayout 中,放置您的 RecyclerViewFloatingActionButton

CoordinatorLayout 应该自动排列您的工具栏、回收器和 fab,因为它被编程为处理设计支持库组件。

这是一个例子。您可以使用 RecyclerView 代替 FrameLayout(在运行时动态加载 fragment )。我通常在另一个 Fragment 中使用 RecyclerView 并在运行时将 fragment 加载到这里。这使 xml 文件保持干净。

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.CoordinatorLayout
android:id="@+id/layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

</android.support.design.widget.AppBarLayout>


<!-- Main layout for fragment placing -->
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >

</FrameLayout>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fabBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action"
android:layout_gravity="bottom|right"
android:layout_marginBottom="@dimen/fab_margin_bottom"
android:layout_marginRight="@dimen/fab_margin_right"
app:fab_colorNormal="@color/pink"
app:fab_colorPressed="@color/pink_pressed"
app:borderWidth = "0dp" />


</android.support.design.widget.CoordinatorLayout>

<!-- Nav drawer -->
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:itemIconTint="@color/pink_pressed"
app:itemTextColor="@color/primary_text"
app:menu="@menu/nav_menu" />

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

关于android - float 操作按钮不显示在 recyclerview 上(位于 DrawerLayout 内),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32546627/

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