I have a FrameLayout that includes a TabLayout and a ViewPager inside it. Obviously the ViewPager loads a fragment. Now the problem is that TabLayout goes under the content of fragment when it's loaded and therefore disappears.
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</FrameLayout>
How do I fix it?
EDIT:
using the following code I was able to make it work but now the tabs are always stuck to the top when scrolling... anyway to fix that?
<LinearLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"/>
</LinearLayout>
Change to a vertical LinearLayout
. Then the ViewPager
will appear beneath the TabLayout
instead of drawing over it.