【发布时间】:2015-12-30 17:28:20
【问题描述】:
我有一个父视图,其根视图是CoordinatorLayout。父布局包含TabLayout 和ViewPager。 ViewPager 包含两个子片段。子片段也有一个CoordinatorLayout 作为它的根视图并包含一个RecyclerView。这是我的 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.v4.view.ViewPager
android:id="@+id/explore_viewpager"
android:layout_width="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_height="match_parent"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/main_activity_appbar"
android:layout_width="match_parent"
app:elevation="2dp"
android:layout_height="wrap_content">
<android.support.design.widget.TabLayout
android:id="@+id/explore_tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways|snap"
android:background="@color/tab_layout_bg"
app:tabIndicatorColor="@color/tab_indicator_color"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
孩子:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/basic_recycler_view_layout_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:scrollbars="vertical"
android:clipToPadding="false"
android:paddingTop="@dimen/single_margin"
android:paddingBottom="@dimen/single_margin"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.design.widget.CoordinatorLayout>
现在,当我尝试从子片段中显示 SnackBar 时,它不会显示并隐藏在屏幕外。如果我滚动子片段,则父片段中的 TabLayout 会折叠(按预期)并出现 SnackBar。我四处搜索,它的行为与此类似:Android Design Support Library FAB in a ViewPager Fragment with Coordinator Layout 除了SnackBar 完全隐藏。我认为这是因为TabLayout 和SnackBar 具有相同的高度。
如何设置布局以显示SnackBar?
这解释起来有点复杂,如果我能澄清任何部分,请告诉我。
【问题讨论】:
标签: android android-fragments android-viewpager android-coordinatorlayout android-snackbar