2016-05-19 14 views
1

ViewPagerはファブの上にスーパーインポーズされています。何よりもファブを入れる方法?フローティングアクションボタンとビューページャ

の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:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    android:layout_margin="@dimen/fab_margin" 
    android:clickable="true" 
    android:src="@drawable/ic_add" 
    android:visibility="visible" /> 

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    android:contextClickable="true"> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/personal_tasks_tabLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:tabSelectedTextColor="#deFFFFFF" 
     app:tabTextColor="#81ffffff" 
     app:tabGravity="fill" /> 
</android.support.design.widget.AppBarLayout> 

<android.support.v4.view.ViewPager 
    android:id="@+id/personal_tasks_viewpager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
</android.support.design.widget.CoordinatorLayout> 

それともそれが理由ではないのか?ただボタンは押されていませんが、タブが裏返しになっています。

答えて

3

CoordinatorLayoutはスーパーFrameLayoutのようなものですので、あなたが上にFABを配置し、あなたがViewPagerを追加する場合、ViewPagerは/カバー以前のビューを重ねます。あなたが試みることができるのは、あなたのFABを底に動かすことです。

<android.support.design.widget.CoordinatorLayout 
    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.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
    android:contextClickable="true"> 

<android.support.design.widget.TabLayout 
    android:id="@+id/personal_tasks_tabLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:tabSelectedTextColor="#deFFFFFF" 
    app:tabTextColor="#81ffffff" 
    app:tabGravity="fill" /> 
</android.support.design.widget.AppBarLayout> 

<android.support.v4.view.ViewPager 
    android:id="@+id/personal_tasks_viewpager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    android:layout_margin="@dimen/fab_margin" 
    android:clickable="true" 
    android:src="@drawable/ic_add" 
    android:visibility="visible" /> 

</android.support.design.widget.CoordinatorLayout> 

また、あなたのViewPager

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    app:layout_anchor="@id/personal_tasks_viewpager" 
    app:layout_anchorGravity="bottom|end" 
</android.support.design.widget.CoordinatorLayout> 
FABを固定しようとすることができます
関連する問題