Я пытаюсь создать список с FAB, чтобы иметь эффект FAB (показать/скрыть) при прокрутке списка.Якорь a FloatingActionButton с ListView
Проблема в том, что мои списки ListView и FAB находятся в разных файлах.
Layout с кнопкой FAB:
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<include layout="@layout/item_list" />
</FrameLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/addForwardFilter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:layout_anchor="@id/custom_list"
app:layout_anchorGravity="bottom|right|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_add" />
</android.support.design.widget.CoordinatorLayout>
Layout item_list.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_list"
android:name="mypackage.test.fragment.FItemListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemListActivity"
tools:layout="@layout/custom_list_content" />
Layout custom_list_content.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/custom_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false" />
</FrameLayout>
Когда я пытаюсь якорь, я получил следующее :
java.lang.IllegalStateException: Could not find CoordinatorLayout descendant view with id mypackage.test:id/custom_list to anchor view android.support.design.widget.FloatingActionButton
Этот пример работает:
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
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">
<ListView
android:id="@+id/lvToDoList"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@drawable/ic_done"
app:layout_anchor="@id/lvToDoList"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
Любые советы?
Я отредактировал мое сообщение. Я приведу пример, который отлично работает с CoordinatorLayout – Emerick