I have the next structure:
Activity 1:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/FAB_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</android.support.design.widget.CoordinatorLayout>
Activity 2:
Form to add new item to the recycler View.
XML of the RecyclerView:
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"/>
I create the item in the second Activity and use startActivityForResult to add the item in the activity one, and then call adapter.notifyItemInserted(0).
The problem is when the item is added, the insert animation does not working properly, but if I don't use the second activity and create the item in the first activity and add to the adapter, it works fine.
¿How can I solve this?
Your xml structure might be the problem, check your layout_behaviors and use of CoordinatorLayout
Android CoordinatorLayout
For a nice guide on how to use CoordinatorLayout and layout_behavior check this blog
I've also found that the use of android:animateLayoutChanges="true" can be very glitchy/buggy in a scrollable RecyclerView, I would suggest not using it. For non-scrollable RecyclerViews it works fine tho.
Related
I want the transition happens after item is removed from the list however when I remove the item transition happens earlier and it covers other items as shown in the GIF below.
my second issue is that when I use layoutTransition, when the fragment is created it expands with animation, how to avoid this at the beginning.
my layout is like like this:
<androidx.core.widget.NestedScrollView
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:fillViewport="true" >
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
and in the Fragment:(Kotlin):
scroll_view.layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
scroll_view.layoutTransition.setStartDelay(LayoutTransition.CHANGING,300)
constraintlayout.layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
constraintlayout.layoutTransition.setStartDelay(LayoutTransition.CHANGING,300)
but nothing changes, always same behavior
I found a way to fix the issue by using custom layout manager :D
the layout manager I used : https://github.com/BelooS/ChipsLayoutManager
I have a NavigationView with a NestedScrollView that contains another NavigationView for the purpose of adding a footer for the NavigationView. The layout code is as follows:
<include layout="#layout/main_content"/>
<android.support.design.widget.NavigationView ...>
<android.support.v4.widget.NestedScrollView
...
android:fillViewport="true"
android:scrollbars="vertical">
<LinearLayout
...
android:orientation="vertical">
<android.support.design.widget.NavigationView
...
app:elevation="0dp"
app:headerLayout="#layout/nav_header"
app:menu="#menu/nav_menu">
</android.support.design.widget.NavigationView>
<LinearLayout
android:id="#+id/spacer_to_bottom"
...
android:layout_height="0dp"
android:layout_weight="1">
</LinearLayout>
<include layout="#layout/nav_footer"></include>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.NavigationView>
Check the full code here: https://github.com/MarcDahlem/AndroidSidemenuFooterExample/blob/master/app/src/main/res/layout/activity_main.xml
The problem is that the scrolling in the NavigationDrawer is not smooth (does not "fling"). In other words, it scrolls while your finger is on the screen and stops when you remove your finger.
I tried disabling nested scroll for the first child (the LinearLayout) of the NestedScrollView but this didn't work.
Any help would be appreciated.
After some investigations I realized that the first child of the navigation view is a RecyclerView. Disabling nested scrolling on that view resolves the issue
ViewCompat.setNestedScrollingEnabled(navigationView.getChildAt(0), false);
There is another way to handle this nested scroll that is;
if you are using nestedscroll view, and using one or more list views/recycler views inside it, we have to enable this;
yourlistview.setNestedScrollingEnabled(true);
It should work now.
I have Recyclerview and Scrollview outside the recyclerview
I want o know how to check if scrollview is scroll to the last(bottom).
If you want to just scrolling then you can use to NestedScrollView instead of ScrollView So you can modify your code with following :
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
//design your content here with RecyclerView
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Also Refer This Link....https://github.com/amardeshbd/android-recycler-view-wrap-content
I am using the following layout, but unable to get the RecyclerView to scroll(it is not visible on the screen when using this layout, scrolling stops till the NestedScrollView).
I can scroll up to the NestedScrollView and the CollapsingToolbar to collapse, if I remove the entire NestedScrollView then I get the RecyclerView to scroll.
If I keep the linear layout without the NestedScrollView, only the RecyclerView scrolls, the rest of the layout is fixed.
I have also added app:layout_behavior="#string/appbar_scrolling_view_behavior" to the RecyclerView, and have kept the RecyclerView out of the NestedScrollView.
If I add the RecyclerView inside the NestedScrollView, the RecyclerView does not appear.
<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="com.example.MainFragment">
<!-- android.support.design.widget.AppBarLayout here
with a android.support.design.widget.CollapsingToolbarLayout
-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<!-- more layout code here -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/large_text"/>
</RelativeLayout>
<View
android:id="#+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorAccent" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewListOfData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="#layout/recycler_view"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</LinearLayout>
Ok, if you want to add RecyclerView inside NestedScrollView add this line into RecyclerView in xml file app:layoutManager="LinearLayoutManager".
Example
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/your_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layoutManager="LinearLayoutManager"/>
</android.support.v4.widget.NestedScrollView>
Then in your SomeActivity.java file where you populate RecyclerView put this line recyclerView.setNestedScrollingEnabled(false); before you setting adapter to RecyclerView.
Example
RecyclerView recyclerView=(RecyclerView)findViewById(R.id.your_recyclerview);
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setAdapter(yourAdapter);
I solved it by nesting RecyclerView inside the NestedScrollView and updating the support library for recyclerview
I was using com.android.support:recyclerview-v7:23.0.1
as of Android Support Library, revision 23.2.0 (February 2016)
(refer revision archive here)
Changes for v7 RecyclerView library:
RecyclerView now has an opt-in feature called AutoMeasure which allows RecyclerView.LayoutManager to easily wrap content or
handle various measurement specifications provided by the parent of
the RecyclerView. It supports all existing animation capabilities of
the RecyclerView.
If you have a custom RecyclerView.LayoutManager, call setAutoMeasureEnabled(true) to start using the new AutoMeasure API.
All built-in RecyclerView.LayoutManager objects enable auto-measure by
default.
RecyclerView.LayoutManager no longer ignores some RecyclerView.LayoutParams settings, such as MATCH_PARENT in the scroll
direction.
Note: These lifted restrictions may cause unexpected behavior in your
layouts. Make sure you specify the correct layout
parameters.
Using com.android.support:recyclerview-v7:23.4.0 solves the problem of nested recyclerview not appearing in nested scroll view
I tend to further elaborate from this
Android - footer scrolls off screen when used in CoordinatorLayout
and
https://code.google.com/p/android/issues/detail?id=177195
I wish to hide TabLayout while performing scrolling on RecyclerView. That's why I have the following layout.
<CoordinatorLayout>
<CollapsingToolbarLayout>
<TabLayout>
<ViewPager>
<RecyclerView>
<Footer>
For my situation, I have a ViewPager which contains multiple fragments.
Most of the fragments, contains RecyclerView and footer. They look like the following
<LinearLayout>
<RecyclerView />
<LinearLayout id="#+id/footer" />
</LinearLayout>
Unfortunately, the footer is movable when scrolling, although I would like it to be static.
Note, it is important to have app:layout_behavior to place in ViewPager instead of RecyclerView. If not, TabLayout will not appear.
My implementation is as follow
my_fragment.xml
<?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/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" >
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways|snap">
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="?attr/portfolioTabIndicatorColor" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="org.yccheok.xxx.CustomScrollingViewBehavior"
/>
</android.support.design.widget.CoordinatorLayout>
The very key class is org.yccheok.xxx.CustomScrollingViewBehavior, which is copied and pasted from https://stackoverflow.com/a/33396965/72437
org.yccheok.xxx.CustomScrollingViewBehavior is the best solution I can find so far. However, it is far from perfect, as it yields the following behavior.
It causes flickering, when you scroll up a little, and release your finger. Please refer to the following video.
https://youtu.be/8RvCZJeQvS0
I was wondering, based on proposed solution at https://stackoverflow.com/a/33396965/72437, is there any further improvement I can done on CustomScrollingViewBehavior class, to avoid flickering effect?
I was able to achieve what I want, by following tutorial at
https://mzgreen.github.io/2015/02/15/How-to-hideshow-Toolbar-when-list-is-scroling%28part1%29/
http://mzgreen.github.io/2015/02/28/How-to-hideshow-Toolbar-when-list-is-scrolling%28part2%29/
The key ideas are
Don't use CoordinatorLayout
Place TabLayout and RecyclerView within FrameLayout, so that TabLayout will overlay on the top of RecyclerView
Add top padding on RecyclerView. Having android:clipToPadding="false" is important as well.
To hide/ show TabLayout during scrolling, attach HidingScrollListener to RecyclerView.
The shortcoming for this solution is that, requiresFadingEdge will no longer work on RecyclerView, due to the top padding.