我无法在 RecyclerView 上显示浮动操作菜单。

huangapple go评论71阅读模式
英文:

I can't display floating action menu on recyclerview

问题

我想在RecyclerView对象上显示浮动操作菜单。我有一个课程活动,用于显示保存的课程。我想在其中添加浮动操作按钮,包括两个选项。当我添加新数据时,如果RecyclerView对象没有数据,我的浮动操作菜单可以正常工作,但是当RecyclerView已满时,它不像页面底部的图片那样工作。我该如何解决这个问题?

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:background="@drawable/bg_login"
    tools:context=".MainActivity">

    <com.github.clans.fab.FloatingActionMenu
        android:id="@+id/floatingActionMenu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_margin="16dp"
        app:menu_backgroundColor="@android:color/transparent"
        app:menu_fab_label=""
        app:menu_openDirection="up"
        app:menu_showShadow="true">

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/floatingAddButtonLesson"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:fab_label="Ders Ekle"
            app:fab_size="mini"
            app:srcCompat="@drawable/ic_add"
            tools:ignore="VectorDrawableCompat" />

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/floatingAddButtonLesson2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:fab_label="Toplam Kaç Soru Çözdüm"
            app:fab_size="mini"
            app:srcCompat="@drawable/ic_add"
            tools:ignore="VectorDrawableCompat" />

    </com.github.clans.fab.FloatingActionMenu>

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:id="@+id/rvLesson"
        android:layout_height="wrap_content" />
</RelativeLayout>

我无法在 RecyclerView 上显示浮动操作菜单。

英文:

I want to display floating action menu on recyclerview object.I have a lesson activity that display to saved lesson. I want to add floating action button its include 2 selection. When i added new dataif recylverview object is no have data my floating action menu is working good but when recyclerview is full its not working like the picture bottom of page. What can i do solved this problem ?

&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;
    android:layout_gravity=&quot;center&quot;
    android:background=&quot;@drawable/bg_login&quot;
    tools:context=&quot;.MainActivity&quot;&gt;

        &lt;com.github.clans.fab.FloatingActionMenu
            android:id=&quot;@+id/floatingActionMenu&quot;
            android:layout_width=&quot;wrap_content&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:layout_alignParentBottom=&quot;true&quot;
            android:layout_alignParentEnd=&quot;true&quot;
            android:layout_alignParentRight=&quot;true&quot;
            android:layout_margin=&quot;16dp&quot;
            app:menu_backgroundColor=&quot;@android:color/transparent&quot;
            app:menu_fab_label=&quot;&quot;
            app:menu_openDirection=&quot;up&quot;
            app:menu_showShadow=&quot;true&quot;&gt;

            &lt;com.github.clans.fab.FloatingActionButton
                android:id=&quot;@+id/floatingAddButtonLesson&quot;
                android:layout_width=&quot;wrap_content&quot;
                android:layout_height=&quot;wrap_content&quot;
                app:fab_label=&quot;Ders Ekle&quot;
                app:fab_size=&quot;mini&quot;
                app:srcCompat=&quot;@drawable/ic_add&quot;
                tools:ignore=&quot;VectorDrawableCompat&quot; /&gt;

            &lt;com.github.clans.fab.FloatingActionButton
                android:id=&quot;@+id/floatingAddButtonLesson2&quot;
                android:layout_width=&quot;wrap_content&quot;
                android:layout_height=&quot;wrap_content&quot;
                app:fab_label=&quot;Toplam Ka&#231; Soru &#199;&#246;zd&#252;m&quot;
                app:fab_size=&quot;mini&quot;
                app:srcCompat=&quot;@drawable/ic_add&quot;
                tools:ignore=&quot;VectorDrawableCompat&quot; /&gt;


        &lt;/com.github.clans.fab.FloatingActionMenu&gt;

    &lt;androidx.recyclerview.widget.RecyclerView
        android:layout_width=&quot;match_parent&quot;
        android:id=&quot;@+id/rvLesson&quot;
        android:layout_height=&quot;wrap_content&quot;/&gt;
&lt;/RelativeLayout&gt;

<a href="https://resimyukle.xyz/i/1dGcfC"><img src="https://i.resimyukle.xyz/1dGcfC.png" /></a>

答案1

得分: 1

你只需将FloatingActionMenu放在RecyclerView下方,然后FloatingActionMenu将显示在顶部RecyclerView上方。

<RelativeLayout 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"
    android:layout_gravity="center"
    android:background="@drawable/bg_login"
    tools:context=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:id="@+id/rvLesson"
        android:layout_height="wrap_content" />

    <com.github.clans.fab.FloatingActionMenu
        android:id="@+id/floatingActionMenu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_margin="16dp"
        app:menu_backgroundColor="@android:color/transparent"
        app:menu_fab_label=""
        app:menu_openDirection="up"
        app:menu_showShadow="true">

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/floatingAddButtonLesson"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:fab_label="Ders Ekle"
            app:fab_size="mini"
            app:srcCompat="@drawable/ic_add"
            tools:ignore="VectorDrawableCompat" />

        <com.github.clans.fab.FloatingActionButton
            android:id="@+id/floatingAddButtonLesson2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:fab_label="Toplam Ka&#231; Soru &#199;&#246;zd&#252;m"
            app:fab_size="mini"
            app:srcCompat="@drawable/ic_add"
            tools:ignore="VectorDrawableCompat" />

    </com.github.clans.fab.FloatingActionMenu>

</RelativeLayout>
英文:

You just need to place FloatingActionMenu below the RecyclerView, then FloatingActionMenu will show on top RecyclerView

&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;
    android:layout_gravity=&quot;center&quot;
    android:background=&quot;@drawable/bg_login&quot;
    tools:context=&quot;.MainActivity&quot;&gt;

        &lt;androidx.recyclerview.widget.RecyclerView
            android:layout_width=&quot;match_parent&quot;
            android:id=&quot;@+id/rvLesson&quot;
            android:layout_height=&quot;wrap_content&quot;/&gt;

        &lt;com.github.clans.fab.FloatingActionMenu
            android:id=&quot;@+id/floatingActionMenu&quot;
            android:layout_width=&quot;wrap_content&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:layout_alignParentBottom=&quot;true&quot;
            android:layout_alignParentEnd=&quot;true&quot;
            android:layout_alignParentRight=&quot;true&quot;
            android:layout_margin=&quot;16dp&quot;
            app:menu_backgroundColor=&quot;@android:color/transparent&quot;
            app:menu_fab_label=&quot;&quot;
            app:menu_openDirection=&quot;up&quot;
            app:menu_showShadow=&quot;true&quot;&gt;

            &lt;com.github.clans.fab.FloatingActionButton
                android:id=&quot;@+id/floatingAddButtonLesson&quot;
                android:layout_width=&quot;wrap_content&quot;
                android:layout_height=&quot;wrap_content&quot;
                app:fab_label=&quot;Ders Ekle&quot;
                app:fab_size=&quot;mini&quot;
                app:srcCompat=&quot;@drawable/ic_add&quot;
                tools:ignore=&quot;VectorDrawableCompat&quot; /&gt;

            &lt;com.github.clans.fab.FloatingActionButton
                android:id=&quot;@+id/floatingAddButtonLesson2&quot;
                android:layout_width=&quot;wrap_content&quot;
                android:layout_height=&quot;wrap_content&quot;
                app:fab_label=&quot;Toplam Ka&#231; Soru &#199;&#246;zd&#252;m&quot;
                app:fab_size=&quot;mini&quot;
                app:srcCompat=&quot;@drawable/ic_add&quot;
                tools:ignore=&quot;VectorDrawableCompat&quot; /&gt;


        &lt;/com.github.clans.fab.FloatingActionMenu&gt;

&lt;/RelativeLayout&gt;

huangapple
  • 本文由 发表于 2020年7月25日 01:40:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/63078783.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定