NestedScrollView in AppBarLayout cut off at screen height - android

I have a AppBarLayout with a NestedScrollView. I am trying to make it display correctly and have a fling effect when it is displayed.
Originally I had this layout:
<FrameLayout>
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
<android.support.design.widget.CollapsingToolbarLayout>
...collapsing content
<android.support.v7.widget.Toolbar/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView>
...scrolling content
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</FrameLayout>
(with the NestedScrollView outside the AppBarLayout) It worked well but I could not fling the content when scrolling.
I used the advice in the accepted answer here, using the layout pattern in the answer referenced by the accepted one and moved the content inside the AppBarLayout. It now flings nicely, but the content contained in the NestedScrollView is cut off at the height of the screen. As you begin to scroll up you immediately see the end of the views despite the content being much longer.
My current Layout is this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
>
... textviews etc
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
</FrameLayout>
I have tried substituting wrap_content with match_height but this doesn't seem to be the problem.
I load all the content into TextViews via a webservice call and call .RequestLayout(); on each TextView after I load the content.
edit
I have moved the NestedScrollView outside the AppBarLayou again. It flings when the AppBarLayout is collapsed, but not while it is open

Related

Wave effect of NestedScrollView inside CoordinatorLayout is not working when scrolling

I made a layout using CoordinatorLayout as a container and NestedScrollView to display my contents.
I used NestedScrollView to hide my toolbar when scrolling down, but the usual wave effect which should be shown below toolbar whenever I try to scroll and reach the limit of the layout is not working.
Here is the
.
How to make this effect? If I use normal ScrollView, this effect will be shown but I can not hide my toolbar.
Here is my layout:
<android.support.design.widget.CoordinatorLayout
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"
android:id="#+id/layout_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.dicoding.paul.moviecatalog.DetailActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ToolbarTheme">
<android.support.v7.widget.Toolbar
android:id="#+id/tb_my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
android:elevation="4dp"
android:theme="#style/ToolbarTheme"
app:popupTheme="#style/ToolbarTheme"
app:layout_scrollFlags="scroll|enterAlways"
app:title="Detail"
app:titleTextAppearance="#style/ToolbarTheme.TitleText"/>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/activity_detail_content"/>
</android.support.design.widget.CoordinatorLayout>
And here is my detail content:
<android.support.v4.widget.NestedScrollView
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="wrap_content"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
//contents
//contents
</android.support.v4.widget.NestedScrollView>
Try this:
android:clipToPadding="false"
In your NestedScollView.

ViewPager taking space below the bar

I have a layout coded like below
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.HomepageActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/header_copy">
<!--android:background="#072120"-->
<!--android:background="#drawable/header_copy-->
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:titleTextColor="#FFFADE09"
app:titleMarginStart="100dp"
app:titleTextAppearance="#style/TabLayoutTextStyle"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="#style/AppTheme.PopupOverlay"
>
<!--android:background="#FF008080"-->
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabGravity="fill"
app:tabTextColor="#FFFADE09"
app:tabSelectedTextColor="#F7FFFFFF"
app:tabTextAppearance="#style/TabLayoutTextStyle" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
But this result the below UX
The viewPager is taking space below the bottom bar. But I do not want this behaviour. I want the viewPager take only that visible screen space. Please help me here.
Since your tab bar will always be at the top, and the rest of the views will be under the toolbar, you can replace CoordinatorLayout for a LinearLayout with orientation="vertical" fixes the overflowing issue.
here you are using android.support.design.widget.CoordinatorLayout, the topmost behavior of CoordinatorLayout is appbar_scrolling_view_behavior so is getting extra space in bottom equivalent to the android.support.design.widget.AppBarLayout size.
in this case, you should use LinearLayout or RelativeLayout instead of android.support.design.widget.CoordinatorLayout

Scrollable Layout on top of ViewPager

I am creating an app with an AppBar and below this one, a (Relative)Layout.
Like in Facebook Messenger :
You can see the AppBar and below it a Layout with three buttons (TOUS, MESSENGER, SMS).
When I scroll, my Layout including the three buttons does not move, it stays "pinned" at the same position (on top). My objective is to make that the Layout with the thress buttons pass behind the AppBar and does not stay in the view.
Here is my actual code :
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways|snap" />
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
app:tabIndicatorColor="#color/fullWhite"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:background="#color/background_grey_white">
<!-- These part has to scroll and pass behind the AppBar when the user is scrolling, but it does not work at the moment, it stays "pinned" at the top of the screen -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="13sp"
android:id="#+id/content_frame">
<include layout="#layout/tous_messenger_sms"/>
</RelativeLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/separator_color"/>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
What do I have to change to make it work ?
Can someone help me? Thank you!
Just move the RelativeLayout into the layout of the first element of the ViewPager. In this way when you swipe, the elements in the RelativeLayout will disappear, because the current tab was changed.

use CoordinatorLayout to hide/show RelativeLayout when scrolling a RecyclerView

I have a layout (as generated by android studio) where i added a RelativeLayout to the AppBarLayout. The code is below and it looks like this:
Where i am stuck: What i want to achieve is when scrolling the Recyclerview down i want that the green relative layout (which has the id 'controlContainer') scrolls out with it, and when i scroll up it should scroll in (not just on the top but at any place i scroll up in the list)
The Toolbar on top should stay where it is.
<android.support.design.widget.CoordinatorLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/AppTheme.PopupOverlay"
/>
<RelativeLayout
android:id="#+id/controlContainer"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#android:color/holo_green_dark"
app:layout_scrollFlags="scroll|enterAlways"></RelativeLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<include layout="#layout/venue_list" />
</FrameLayout>
I thought that using app:layout_scrollFlags="scroll|enterAlways" in the view that should scroll away combined with app:layout_behavior="#string/appbar_scrolling_view_behavior"should achieve that, but it does not do anything. alternatively, when i add those fields to the toolbar itself both layouts scroll away - which is not what i want, i want the toolbar to stay always fixed.
would be nice if anyone could point me in the right direction here? (i hoped it would be possible with using coordinator layout and not hacking some layout manipulation with onscroll listeners?)
Try this in your toolbar code:
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"
I found this link helpful: Scrolling Toolbar

Disabling android CoordinatorLayout scrolling behaviour

When adding scrolling behaviour to a layout with coordinatorLayout like this:
<android.support.design.widget.CoordinatorLayout
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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/mainContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
the mainContent is the part that matters.
The real layout will be inflated inside this container.
Imagining my View consists of a RecyclerView, and a fixed layout at the bottom of the screen.
Does someone know a way to remove the scrolling behavior of the bottom fixed layout and keep the RecyclerView-Toolbar-hide behaviour?
Inside a 'CoordinatorLayout' the views that scroll must be first and only later the non-scrollable views. I managed to solve the issue by placing my non-scrollable layout outside the 'mainContent', just below it

Categories

Resources