在片段列表中的listview下添加浮动按钮

时间:2017-11-19 22:07:11

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

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

这是我的片段xml代码

lineViews

我试图以这种方式添加FloatingActionButton

  <ol class="carousel-indicators">
    <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
    <li data-target="#myCarousel" data-slide-to="1"></li>
    <li data-target="#myCarousel" data-slide-to="2"></li>
  </ol>

  <div class="carousel-inner" role="listbox">
    <div class="item active">
        <img src="img/mountains.png">
        <div class="carousel-caption">
          <h1>Lorem Ipsum</h1>
          <br>
          <button type="button" class="btn btn-default">Lorem Ipsum</button>
        </div>
    </div> <!-- Kraj active slajdera -->
    <div class="item">
      <img src="img/snow.png">
    </div>
    <div class="item">
      <img src="img/red.png">
    </div>
  </div>
  <!-- Strelice Pocetak -->
  <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div> <!--Kraj slajdera -->

1 个答案:

答案 0 :(得分: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>