NestedScrollView not respecting childs height - android

I have a collapsing layout with tab layout and view pager.
Inside the viewpager, in the first tab, I have a NestedScrollView with a lot of children. The problem is: the NestedScrollView is not respecting the children height.
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScrollView"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:isScrollContainer="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:fillViewport="true"
android:background="#color/colorBlack"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="#+id/relative"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:paddingRight="16dp"
android:paddingLeft="16dp"
android:clipToPadding="false">
.... Lots of children
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
The last TextView of this LinearLayout doesn't show. If I put a margin bottom in the TextView of 50dp, it does show.
What I'm missing?
Full code: https://gist.github.com/guuilp/81f06c8a5581d2a9ce0a19dcf6c12ccc

Related

View Pager contents not showing

On my Home Fragment it contains
ScrollView
LinearLayout
RecycleView
LinearLayout
TabsLayout
ViewPager
TextView (Just to test if the height of ViewPager was updated)
When opening the home screen it will show the Recycle View, Tabs Layout and Text View does not include the View Pager (I did confirm that the adapter was executed properly but the content does not show)
I did try to remove the visibility of the RecycleView and after that
the ViewPager Contents shows up.
fragment_home.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fillViewport="true"
xmlns:tools="http://schemas.android.com/tools"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/item_listing"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:clipChildren="false"
tools:listitem="#layout/item_categories_content"/>
<include
layout="#layout/fragment_home_news_events"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
fragment_home_news_events.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:orientation="vertical">
<com.google.android.material.tabs.TabLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/activity_margin"
app:tabSelectedTextColor="#color/colorPrimary"
android:id="#+id/fragment_home_inner_tabs">
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager.widget.ViewPager
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/fragment_home_inner_tabs_content">
</androidx.viewpager.widget.ViewPager>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/text_label_status"/>
</LinearLayout>
When the RecycleView is visible
When the RecycleView is not visible
You have RecyclerView with include of another layout (fragment_home_news_events) the two had match_parent in height :(
try to fix height to fragment_home_news_events not match_parent.
or
put the height 0dp for both RecyclerView and fragment_home_news_events but with weight 1.

Nested scroll view elements are not scrolling

I have relative layout in nested scroll view and under relative layout I have view pager tablayout and recycler view. My problem is nested scroll view elements are not scrolling view pager is fixed on top while recycler view is scrolling below view pager.I want to scroll view pager also in layout.
This is my code below:
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".Home"
android:orientation="vertical"
android:id="#+id/linearHome"
android:paddingBottom="16dp"
android:layout_marginTop="10dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:layout_marginBottom="50dp">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progress2"
android:layout_centerInParent="true"/>
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:id="#+id/nobook"
android:src="#drawable/nobook"
android:layout_centerInParent="true"
android:visibility="gone"/>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="130dp"
android:id="#+id/homeOffers"/>
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/homeOffers"
android:id="#+id/indicator"
app:tabGravity="center"
app:tabIndicatorHeight="0dp"
app:tabBackground="#drawable/tab_selector"/>
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/indicator"
android:id="#+id/refresh">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/recycle"/>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
Someone please let me know how to get desired layout. Any help would be appreciated.
THANKS
You can change your parent layout and use ScrollView as a child.
Your current layout:
{NestedScrollView}(Which is your parent) -->{RelativeLayout} -->{ProgressBar, ImageView,ViewPager etc}
After changing your parent to the relative layout :
{RelativeLayout}(Which is now your new parent layout. Everything else remains the same)-->{ScrollView}(which preveously was your NestedScrollView) -->{RelativeLayout} -->{ProgressBar, ImageView,ViewPager etc}
Try this - app:layout_behavior="#string/appbar_scrolling_view_behavior" property to the SwipeRefreshLayout.

ImageView causes NestedScrollView to automatically scroll upward

I have an ImageView inside RelativeView that is inside NestedScrollView, when I set the ImageView height it causes the an automatic upward scroll right after the inflation. This behaviour doesn't happen when I set the ImageView height to be wrap_content. What could be the reason? Is this some kind of bug in the support library?
Notes:
If I kept the ImageView height as 170 & removed the RelativeLayout this upward auto-scroll doesn't happen.
If I kept the RelativeLayout & set ImageView height to wrap_content this upward auto-scroll doesn't happen.
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.mydomain.test">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="170dp"
android:scaleType="fitXY"
android:src="#drawable/cover"/>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Update & Fix:
Adding android:descendantFocusability="blocksDescendants" to the vertical LinearLayout fixed the problem to be:
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.mydomain.test">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp"
android:descendantFocusability="blocksDescendants">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="170dp"
android:scaleType="fitXY"
android:src="#drawable/cover"/>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
I found the solution and the reason of the problem, In the code above I have the RelativeLayout inside a vertical LinearLayout, and when I added
android:descendantFocusability="blocksDescendants"
to the vertical LinearLayout, the problem got fixed.

Update NestedScrollView layout

Here is my layout:
CoordinatorLayout
NestedScrollView
LinearLayout
TextView
TextView
TextView
If I change the visibility of the textviews (visible/gone) the LinearLayout and the NestedScrollView should change their height but they do only until the next scheduled layout measuring pass.
So for several second the NestedScrollView has an incorrect scrolling height.
How to update the NestedScrollView (scrolling) height when I change the layout's inside the LinearLayout?
Here is xml:
<android.support.design.widget.CoordinatorLayout
android:id="#+id/coordinatorLayout"
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.support.v4.widget.NestedScrollView
android:id="#+id/filters_detail_view"
android:layout_width="match_parent"
android:layout_height="250dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:id="#+id/filter_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical" >
<TextView
android:id="#+id/title_types"
android:layout_marginLeft="#dimen/padding_tiny"/>
...
...
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

Disable scroll of recyclerview (inside viewpager) untill its fully visible (viewpager is in scrollview)

I have a layout similar to the one shown in image below.
Layout Explained
<ScrollView>
<LinearLayout>
...
</LinearLayout>
<ViewPager>
</ScrollView>
ViewPager has a height equal to the height of screen below ActionBar.
While scrolling, when half of the viewPager is visible.. Vertical scroll of RecylerView of fragment in ViewPager interferes with the main scroll of ScrollView.
I want a solution that makes sure the scroll of RecyclerView inside viewpager is disabled untill the viewpager is fully visible.
Main.xml
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/footer"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_marginLeft="#dimen/secondary_margin"
android:layout_marginRight="#dimen/secondary_margin"
android:id="#+id/scroll_view">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/home_deals_slider" />
<include layout="#layout/top_selling_slider" />
...
<TabLayout>
<android.support.v4.view.ViewPager
android:id="#+id/fragments_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/fragments_view_pager_tab" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Fragment.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/staggered_grid_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</RelativeLayout>
...

Categories

Resources