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">
Related
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
I have a CoordinatorLayout with an AppBarLayout to collapse/expand the Toolbar on scroll. The content view is a NestedScrollView with RecyclerViews (which scroll horizontally) and some other views without scrollviews. Pretty similar to the Airbnb app.
<android.support.design.widget.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.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="#layout/toolbar_flat" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/newstedScrollView"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/consistentGreyWhite"
android:paddingBottom="#dimen/activity_vertical_margin"
android:clipToPadding="false"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/home_slider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/consistentWhite"
android:clipToPadding="false"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="14dp"
android:paddingRight="14dp"
android:paddingTop="#dimen/activity_vertical_margin"
/>
<... other elements ...>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
If I scroll on an element without scrollviews the toolbar collapse/expand works. But if I perform a scroll (vertical) on a RecyclerView the toolbar doesn't work as expected. Seems like the RecyclerViews don't pass the scroll events to the CoordinatorLayout.
I too had this problem.
Add this property to your NestedScrollView tag
app:layout_behavior="#string/appbar_scrolling_view_behavior"
Also, do the following for each recyclerView object in your fragment or activity. And also in your adapter if you are nesting recycler_views'.
recyclerView.setNestedScrollingEnabled(false);
Add this property to your Recycler View.
app:layout_behavior="#string/appbar_scrolling_view_behavior"
Also you can add this to Recycler View.
mRecyclerView.setNestedScrollingEnabled(false);
Like this.
<android.support.v7.widget.RecyclerView
android:id="#+id/home_slider"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Also same thing for NestedScrollView with android:fillViewport="true".
You may use android:fillViewport="true" to make NestedScrollView measure the RecyclerView.
<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">
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>
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>
I'm having weird issues with ScrollView that contains a relativeLayout with topMargin
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="beforeDescendants"
android:fillViewport="true"
android:focusableInTouchMode="true">
<RelativeLayout
android:id="#+id/cp_editor_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:layout_marginTop="270dp"
>
...
This code example does not work. the scrolling stops after around 20px. If i'm removing the margin_top attribute then the scrolling works as expected.
Thanks for your help
I do not understand the issue with the topMargin stopping the scrolling. However, to achieve the desired margin and maintain the scrolling functionality i can think of two solutions:
1) add an extraneous View that has the same height as the margin you want, and put it above your Relative Layout (cp_editor_layout). It would look like this:
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="beforeDescendants"
android:fillViewport="true"
android:focusableInTouchMode="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="270dp" />
<RelativeLayout
android:id="#+id/cp_editor_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white" >
</RelativeLayout>
</LinearLayout>
2) give the margin top margin to your scroll view since that space is unnecessary to have in the scroll anyway. If your going for some type of overscroll you need to subclass the ScrollView.
Hope this helps you somehow :)