Update NestedScrollView layout - android

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>

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.

NestedScrollView not respecting childs height

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

Child inside NestedScrollView not cover full height of screen

I am using NestedScrollView in my fragment. In my xml inside a RelativeLayout but it is not covering full height of screen.
Below is my code -
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:background="#color/black"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:background="#color/red_error_color"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
when run the code only black background is visible but not red as my child view background is red.
Thanks in advance
Try to add this line of code on your nestedscrollview
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
Remove:
android:fitsSystemWindows="true"

FrameLayout does not match the height of NestedScrollView

I have a FrameLayout inside a NestedScrollView, as
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">
But the FrameLayout is not filling the height of the NestedScrollView. How might I fix this?
Check This Solution
Use fillViewport="true"
this attribute causes the scroll view’s child to expand to the height of the ScrollView if needed. When the child is taller than the ScrollView, the attribute has no effect.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">

Overlap sibling view with RelativeLayout

I have a RelativeLayout at the top of my app. Below the RelativeLayout I have a ViewPager.
To explain this in a way that will make sense, imagine the screen's height is 700 pixels. The RelativeLayout is about 200 pixels high.
I want the RelativeLayout to be position absolutely at the top of the app such that the ViewPager is behind it. I then want to add a 200 pixel paddingTop to the ViewPager so that it appears under the RelativeLayout.
Here is the layout I have now (which is obviously not working):
<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">
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
</RelativeLayout>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
I load a ListView with some data under the header:
<LinearLayout
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">
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
How can I do this?
Try changing the linearlayout to a framelayout. This will allow the views to be placed on top of each other.
Then put the code for the pageviewer above the relativelayout. This will make the pageviewer appear to be behind the relativelayout as it is rendered first, and the relativelayout rendered on top of it. Android will render views in the order in which they are declared.
Lastly, add a top margin/padding to the pageviewer to make it seem positioned below the relativelayout.
Here's what you can do:
Use RelativeLayout instead of LinearLayout as the root.
Move the ViewPager(pager) view to the top of child RelativeLayout(header)
<RelativeLayout
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.view.ViewPager
android:id="#+id/pager"
android:paddingTop="200px"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
</RelativeLayout>

Categories

Resources