Showup strange space (gap) when use RecyclerView inside NestedScrollview - android

I'm trying to build a BottomSheet that contains a RecyclerView in it. I used a NestedScrollView and set its behavior as "bottom_sheet_behavior". The first time the app run, it's popping up normally, but when I collapse the BottomSheet and select an item from the spinner, it popping up with a space below it.
This is just happening on android 8, not the other versions.
On the other hand, when I remove RecyclerView, it works normally.
<?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:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.toptoche.searchablespinnerlibrary.SearchableSpinner
android:id="#+id/spinner"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="200dp"
android:background="#c9c5c5"
android:elevation="8dp"
android:entries="#array/seasons"
android:layoutDirection="rtl"
android:spinnerMode="dialog"
android:textAlignment="center"
android:textDirection="rtl" />
</LinearLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="300dp"
android:fillViewport="true"
android:background="#color/colorPrimary"
android:elevation="6dp"
app:layout_behavior="#string/bottom_sheet_behavior">
<android.support.v7.widget.RecyclerView
android:id="#+id/activity_Recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
First run
After select an item from spinner

After a long effort finally found the problem. That was because of using this library ==> Searchable Spinner . I replaced it with simple spinner and it works fine!
Point:: Always use updated and supported libraries :|

Related

Kotlin - Keep button sticky in AppBarLayout$ScrollingViewBehavior (in FragmentContainerView)

I have an issue with FragmentContainerView, it looks like this:
<androidx.fragment.app.FragmentContainerView
android:id="#+id/myFragment"
android:name="com.me.MyFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
And in its fragment, I have a recycler view, and a button:
<RelativeLayout 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">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<Button
android:id="#+id/myBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:gravity="bottom|center" />
However, when I am scrolling, button is also moving up, even though I set up alignParentBottom. I believe the issue is in this line of code:
app:layout_behavior="#string/appbar_scrolling_view_behavior"
which is actually:
<string name="appbar_scrolling_view_behavior" translatable="false">com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior</string>
FragmentContainerView is used in CoordinatorLayout. Note that button is out of SwipeRefreshLayout, so it shouldn't be affected by scrolling the recycler view.
I want to keep it sticky, so it doesn't move when I scroll the screen.
Any ideas?

RecyclerView inside NestedScrollView is not scrolling up when Image is collapsed

Here is a link to the whole project so that you can reproduce the problem:
https://github.com/FaridArbai/TapExchange/tree/master/TapExchange
I would like to ask for help with an issue that I've been struggling with for about two days and yet found no solution in spite of the thorough research that I have done.
Basically, I have an AppBarLayout with a CollapsingToolbarLayout inside whose mission is to collapse a background image when the user scrolls down a RecyclerView of CardViews. The problem arises when I try to scroll down that RecyclerView once the Image is fully collapsed: It won't scroll if I touch one of the cardviews that compose the RecyclerView!
Here is the look with no collapse (here I can scroll with no problem):
Uncollapsed Image, able to scroll in any direction
And here is the look once the image is collapsed (here I cannot scroll down if my finger touches any cardview that compose the RecyclerView):
Collapsed Image, unable to scroll down if I touch one of the cardviews
The code for the whole layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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"
tools:context=".profiles.PersonalProfile"
android:background="#FCFCFC">
<android.support.design.widget.AppBarLayout
android:id="#+id/personal_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/personal_collapsing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:contentScrim="?attr/colorPrimary"
app:title=""
app:titleEnabled="false">
<ImageView
android:id="#+id/personal_image_background"
android:layout_width="match_parent"
android:layout_height="340dp"
android:scaleType="centerCrop"
android:src="#drawable/profile_background"/>
<android.support.v7.widget.Toolbar
android:id="#+id/personal_toolbar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Space
android:id="#+id/avatar_collapsed_target"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="0dp"/>
<TextView
android:id="#+id/personal_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:text="Unknown Username"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/section_selection_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#drawable/ic_action_add" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/personal_image_foreground"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="120dp"
android:layout_gravity="top|center_horizontal"
android:src="#drawable/executive"
app:collapsedTarget="#id/avatar_collapsed_target"
app:layout_behavior="com.faridarbai.tapexchange.graphical.CollapsingAvatarBehavior"
android:elevation="5dp"/>
<LinearLayout
android:id="#+id/personal_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_anchor="#id/personal_image_foreground"
app:layout_anchorGravity="bottom|center"
android:paddingTop="30dp">
<TextView
android:id="#+id/username_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unknown Username"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</LinearLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/personal_nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:fillViewport="true">
<android.support.v7.widget.RecyclerView
android:id="#+id/personal_sections_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="0dp" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
I am building with the API 25 and using GUI utilities from version 25.4.0. I would be extremely grateful if anybody can help.
Thanks
EDIT
I tried with SDK nÂș 27 and 27.1.1 building tools, supressed both "snap" and the NestedScrollView and still got the same problem: Once the background image has collapsed the RecyclerView is unable to scroll up if I initially put my finger on a CardView from the RecyclerView. This is quite odd because WhatsApp, Facebook and Telegram use a very similar Layout and they don't have this problem so there should be a well accepted work around.
Anyone to help?
why you are using RecyclerView inside NestedScrollView?!. if yo have more items with different layouts you can use recyclerView With different ViewTypes but i won't recommend to use it inside NestedScrollView try to use it Directly and don't forget to put this app:layout_behavior="#string/appbar_scrolling_view_behavior" in the recylerView and it will work.

ScrollView slow scroll and items disappearing

I'm trying to add a ScrollView to hold a header and a RecyclerView.
<ScrollView
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="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/profile"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="100dp"
android:background="?attr/colorPrimary">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageView"
android:adjustViewBounds="true"
android:cropToPadding="false" />
</RelativeLayout>
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:scrollbars="none"
android:layout_alignParentLeft="true" />
</RelativeLayout>
</ScrollView>
But I had 2 problems trying this:
The relative layout id/profile is disappearing. When I open the activity it appears for 1 sec and disappears.
The RecyclerView scroll is too slow.
any ideas?
By default, RecyclerView has its own scroll, which conflicts with your ScrollView. To fix it, change the the ScrollView to NestedScrollView.
Put recyclerView in NestedScrollView in XML
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_pracstice_loaction"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none" />
</android.support.v4.widget.NestedScrollView>
And in Activity :
recyclerView.setNestedScrollingEnabled(false);
Surely, You will get what you want. This will solve your Recyclerview Scrolling Problem
Add below code in your activity it will solve your Automatically Scroll Problem.
recyclerView.setFocusable(false);
recylerview.setNestedScrollingEnabled(false);
please set this property of recylerview.
You can check out this project. Its not a Library. Its a Demo code...I Think what you are searching for
check out here https://github.com/kmshack/Android-ParallaxHeaderViewPager
change your scrollview to NestedScrollView.
The relative layout id/profile is disappearing. when I open the
activity it appears for 1 sec and disappear.
Your recyclerview is loading itens hover the relativeLayout, so, add this in your recyclerview:
android:layout_below="#+id/profile"
The recyclerview scroll is too slow.
Just add the code below in your activity:
recylerview.setNestedScrollingEnabled(false);

The item position in the RecyclerView is not saved

I use the mode adjustResize, RecyclerView and EditText, when the keyboard appears, the window shrinks but the visible elements in the RecyclerView go down.
The structure of the layout looks like this:
<LinearLayout
android:orientation="vertical">
<android.support.v7.widget.RecyclerView />
<LinearLayout
android:orientation="vertical"
android:layout_gravity="bottom"/>
</LinearLayout>
I set setStackFromEnd to true, in LinearManager but it does not help.
Versions of libraries: 25.3.0
How can this unpleasant problem be avoided?
instead of using linear layout on top use Relative layout like following...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/bottom_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/bottom_view"/>
</RelativeLayout>

Android Nougat: Bottom layout hides behind Nexus navigation buttons when using ViewPager

While my application has been working fine on Android 4.3 - Android 6, on Android 7 the same design is not working anymore.
What should happen:
What actually happens on Nougat:
If the TextView has a margin of its height, it would show as expected on Nougat, however it wouldn't be on the bottom pre-Nougat.
This only occurs if this fragment is in a ViewPager. Otherwise it shows just fine.
XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="48dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CONTENTS HERE"/>
</ScrollView>
<TextView
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:visibility="gone"
android:text="YOU CANNOT SEE ME"/>
</FrameLayout>
Note: It does not happen on Android Studio's design view, only on the real device. This screenshots are a replica of what happens on a real device.
Anyone has an idea?
Found a fix.
I was using
<android.support.v4.view.ViewPager
android:id="#+id/vpTabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:background="#android:color/white" />
By removing the layout behavior, it was fixed.
<android.support.v4.view.ViewPager
android:id="#+id/vpTabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white" />

Categories

Resources