私は、ViewPagerの中にあるFragment内のAndroid Design Support Libraryからフローティングアクションボタンを取得しようとしています。私は4つのタブを持っていて、タブの1つのみにFABが必要です。次のように私のレイアウトは以下のとおりです。Android Design Support Library FAB ViewPagerのコーディネーターレイアウトのフラグメント
main_layout.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<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:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
app:tabIndicatorHeight="3dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
list_fragment_with_fab.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="5dip"
android:background="@color/Transparent_White"
android:fitsSystemWindows="false"
android:layout_width="match_parent"
android:layout_height="match_parent">
<org.lucasr.twowayview.widget.TwoWayView
android:id="@+id/clip_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:twowayview_layoutManager="ListLayoutManager" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/add_list_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="@drawable/ic_list_add"
app:layout_anchor="@+id/clip_recycler_view"
app:layout_anchorGravity="bottom|right|end" />
さて問題は、ありますFABは設計仕様通り動作しません。ファブの隠蔽と表示は機能しません。また、FABはフラグメントがアクティブ化されたときの最初の場所ではありません。私はそれをより明確にするために以下のスクリーンショットを添付しました。
ご覧のとおり、FABは画面外です。スクロールするとツールバーが非表示になり(Playストアアプリと思う)、タブが残っているとFABが上にスクロールします。これは、設計サポートライブラリのバグ
ですか?またはレイアウトが間違っていますか?また、私はFABをフラグメントの1つにしか入れたくないので、main_layout.xmlに追加するとその目的を破ることができます。
あなたは、あなたのレイアウトでgone' 'に可視性を設定でき、これは私が別のプロジェクトで使用されるものですあなたの断片のfab.setVisibility(View.VISIBLE) 'を設定してfab – hornet2319