【问题标题】:Add floating button under listview in fragment list在片段列表的列表视图下添加浮动按钮
【发布时间】:2018-05-03 02:39:48
【问题描述】:

我有一个包含一个主要活动和一些片段的应用程序,每个片段都是一个列表片段,但是在其中一些片段中,我需要添加一个带有自定义操作的 FloatingActionButton,我想保留自动生成的适配器那个清单。 如果我将 FloatingActionButton 直接添加到列表消失的 xml 中,我该如何添加按钮?

这是我的片段 xml 代码

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView 
    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/list"
    android:name="it.ivannotarstefano.cojule.activity.PlayerFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    app:layoutManager="LinearLayoutManager"
    tools:context="it.ivannotarstefano.cojule.activity.PlayerFragment"
    tools:listitem="@layout/fragment_player" >

</android.support.v7.widget.RecyclerView>

我已经尝试以这种方式添加 FloatingActionButton

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView 
    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/list"
    android:name="it.ivannotarstefano.cojule.activity.PlayerFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    app:layoutManager="LinearLayoutManager"
    tools:context="it.ivannotarstefano.cojule.activity.PlayerFragment"
    tools:listitem="@layout/fragment_player" >

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="10dp"
        android:clickable="true"
        android:focusable="true"
        android:src="@drawable/ic_add_black_24dp"
        app:backgroundTint="#fff700" />

</android.support.v7.widget.RecyclerView>

【问题讨论】:

    标签: android android-layout listview android-fragments floating-action-button


    【解决方案1】:
    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout 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.v7.widget.RecyclerView 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/list"
            android:name="it.ivannotarstefano.cojule.activity.PlayerFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            app:layoutManager="LinearLayoutManager" />
    
        <android.support.design.widget.FloatingActionButton
            android:id="@+id/floatingActionButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="10dp"
            android:baselineAlignBottom="true"
            android:clickable="true"
            android:focusable="true"
            android:src="@drawable/side_nav_bar"
            app:backgroundTint="#fff700" />
    
    </FrameLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多