Reputation: 1272
I've got a CoordinatorLayout with an AppBarLayout and a collapsible TabLayout. I've got a ViewPager for my content. This is the working hierarchy so far:
<CoordinatorLayout>
<AppBarLayout>
<Toolbar />
<TabLayout />
</AppBarLayout>
<ViewPager />
</CoordinatorLayout>
Now I want to have a Fragment at the bottom which I can hide. When the bottom fragment is hidden the ViewPager should take all available space. When the bottom fragment is visible no parts of the ViewPager should be obfuscated.
This is the first try:
<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>
Using this layout, the bottom part of my ViewPager is obfuscated when the frame layout is visible. Giving the ViewPager a bottom margin with the FrameLayouts height I always have a blank space at the bottom even if the FrameLayout is gone.
I tried to wrap the ViewPager and the FrameLayout in a LinearLayout but then the top part of the ViewPager is behind the AppBar when the FrameLayout for the fragment is visible.
Can anybody help?
Upvotes: 1
Views: 819
Reputation: 31468
I'm not 100% sure if I understand your issue, but why don't you try this:
<CoordinatorLayout>
<AppBarLayout>
<Toolbar />
<TabLayout />
</AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<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"/>
</LinearLayout>
</CoordinatorLayout>
ViewPager's
layout_width
and layout_weight
are really important, so copy those exact values.
Upvotes: 1