【发布时间】:2015-12-08 07:43:59
【问题描述】:
我有一个带有 AppBarLayout 和一个可折叠 TabLayout 的 CoordinatorLayout。我的内容有一个 ViewPager。这是目前的工作层次结构:
<CoordinatorLayout>
<AppBarLayout>
<Toolbar />
<TabLayout />
</AppBarLayout>
<ViewPager />
</CoordinatorLayout>
现在我想在底部有一个可以隐藏的片段。当底部片段被隐藏时, ViewPager 应该占用所有可用空间。当底部片段可见时,不应混淆 ViewPager 的任何部分。
这是第一次尝试:
<CoordinatorLayout>
<AppBarLayout>
<Toolbar />
<TabLayout />
</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" />
<FrameLayout
android:id="@id/fragmentContainer"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="bottom"
android:background="@android:color/background_light"
android:elevation="@dimen/action_bar_elevation"/>
</CoordinatorLayout>
使用这种布局,当框架布局可见时,我的 ViewPager 的底部会被混淆。给 ViewPager 一个带有 FrameLayouts 高度的底部边距,即使 FrameLayout 消失了,我的底部也总是有一个空白区域。
我尝试将 ViewPager 和 FrameLayout 包装在 LinearLayout 中,但是当片段的 FrameLayout 可见时,ViewPager 的顶部位于 AppBar 后面。
有人可以帮忙吗?
【问题讨论】:
标签: android android-layout android-fragments