0

We have layout file something similar to below:

<androidx.core.widget.NestedScrollView
              android:fillViewport="true"
              app:layout_behavior="@string/appbar_scrolling_view_behavior"
              android:layout_width="match_parent"
              android:layout_height="0dp">
    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent">
        <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent">
            <CheckBox android:id="@+id/checkboxId"
              android:layout_width="match_parent"
              android:layout_height="match_parent" />
            <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:visibility="gone"></LinearLayout>
            <androidx.coordinatorlayout.widget.CoordinatorLayout
             android:layout_width="match_parent"
             android:layout_height="match_parent">
                <androidx.viewpager.widget.ViewPager
                  android:id="@+id/view_pager"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"/>
                <com.google.android.material.appbar.AppBarLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content">
                    <com.google.android.material.tabs.TabLayout
                      android:id="@+id/tab_layout"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content">
                        <com.google.android.material.tabs.TabItem
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:text="Overview" />
                        <com.google.android.material.tabs.TabItem
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:text="Details" />
                    </com.google.android.material.tabs.TabLayout>
                </com.google.android.material.appbar.AppBarLayout>
            </androidx.coordinatorlayout.widget.CoordinatorLayout>
        </LinearLayout>
    </LinearLayout>
</androidx.core.widget.NestedScrollView>

Given:

If you noticed, there is checkbox view in the layout which toggles the LinearLayout visibility from GONE to VISIBLE and vice versa.

Problem

It works fine with initial state of Layout as "GONE" but when linear layout is set to visible using checkbox, the fragment for TabLayout are cutting off (As per screenshot, not able to scroll down) enter image description here

My Viewpoint

Looks like ViewPager is taking some fixed height and when Linear layout shows up(VISIBLE) it breaks. Any clue how would this be resolved ?

AfterMath

However, If I fixed the height (say 400dp) of CoordinatorLayout it shows up fine. enter image description here

Vivek Pratap Singh
  • 9,326
  • 5
  • 21
  • 34
  • It would be great If you could attach screenshots. – vishalsehgal Jun 15 '20 at 17:41
  • @codervishal Added! – Vivek Pratap Singh Jun 15 '20 at 17:56
  • Seems like a problem with your ViewPager's height set it wrap_content and try creating a custom ViewPager with overriding its onMeasure method like this, https://stackoverflow.com/a/20784791/9617459 – vishalsehgal Jun 15 '20 at 18:20
  • I tried it didn't work. I think problem with NestedScrollView. Look like it didn't even consider viewPagers element inside it to resize itself. I added few sample textview inside one of the TabView's fragment but still it chopping off (not scrolling down) without even considering checkbox case. – Vivek Pratap Singh Jun 15 '20 at 18:49

0 Answers0