I am using a ViewPager in a CoordinatorLayout (from latest version of Design Library) in an Activity. Some fragments for this ViewPager have layouts such as RecyclerView or NestedScrollView, but some just cannot scroll given their small content.
<android.support.design.widget.AppBarLayout
android:id="@+id/tabanim_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/MyTheme">
<android.support.v7.widget.Toolbar
android:id="@+id/tabanim_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabanim_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/tabanim_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
But in one Fragment with a FrameLayout as the root view, I need to have a button that is anchored to the bottom, but it appears to be drawn off-screen. To be able to see it, I need to add a bottom padding equals to the height of the Toolbar.
<FrameLayout 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:background="@android:color/white">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Home screen"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_gravity="bottom"
android:gravity="center"
android:text="@string/brand"
android:textColor="@color/brandColor"
android:textSize="20sp" />
</FrameLayout>
Likewise, a layout_gravity set to 'center' on an element does not appear to be in the center of the visible area for this fragment.
My understanding is that CoordinatorLayout is only intented to work with scrolling contents, is that correct ? So that using only regular ViewGroup such as FrameLayout, RelativeLayout, LinearLayout for the ViewPager fragments will have their bottom part drawn off-screen ?
In that case, do I need to remove this button from this fragment layout and move it to the activity layout containing the CoordinatorLayout ? It needs to be shown only on the first fragment.