SwipeRefreshLayout - Pull From Bottom - android

Is there a way to use SwipeRefreshLayout to refresh ListView when it's pulled from bottom?
I created pull from top, but I would also need pull from bottom. There are many tutorials on how to create pull from top, but I couldn't find any tutorials for pull from bottom?

SwipeRefreshLayout from Android Support Library version 21 does not support pull from bottom.
I have made modification SwipeRefreshLayoutBottom with is based on original SwipeRefreshLayout code.
It is fully based on original Google code with just inversion of coordinates and overridden implementation of canChildScrollDown method. All modification are marked as TODO.
Bitbucker repository

Use this great library:
OrangeGangsters SwipyRefreshLayout
So you can swipe both from top and bottom and supports API 9+.

Library omadahealth/SwipyRefreshLayout must be the answer for your case.
Below Codes make your Recycler view pull up from bottom to refresh :
<com.omadahealth.github.swipyrefreshlayout.library.SwipyRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/refresh_layout"
style="#style/View_MatchParent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:srl_direction="bottom"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
style="#style/View_MatchParent"
android:layout_height="wrap_content"
android:clipToPadding="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
</com.omadahealth.github.swipyrefreshlayout.library.SwipyRefreshLayout>

I've encountered the same problem and I have solved it with a combination of swipeRefreshLayout and a touch event in my list. Here is the link:
https://stackoverflow.com/a/41701320/6144027

No, you can't do that with SwipeRefreshLayout. You need to implement your own layout, which is not that hard.
Check this
http://erikw.eu/open-source-android-pull-to-refresh-library/
and this
http://www.oodlestechnologies.com/blogs/Implementing-Pull-to-refresh-(like-in-Facebook-mobile-app)-for-ANDROID-using-Titanium

Related

Having RecyclerView inside a NestedScrollView calls onBindView for all the items

I have two RecyclerViews placed vertically in a LinearLayout. I need to make both of them scrollable and that is why I have put the LinearLayout inside NestedScrollView
This is the my layout file.
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/featured_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:id="#+id/all_topic_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Also, I am disabling nested scrolling in Java code.
disableNestedScrolling(findViewById(R.id.all_topic_list));
disableNestedScrolling(findViewById(R.id.featured_list));
My RecylerView library version is 26.1.0
This works fine perfectly, but then onBindViewHolder method is getting called for all the items in the list. Ideally it should only be called for the visible items in the list.
I think the issue is happening because I am giving wrap_content to the RecyclerView. A lot of answers on this question suggest that the issue is solved in v23.2.1, but I am already using v26.1.0. How to solve this issue?
I had exactly the same problem. RecyclerViews are not meant to be placed inside scroll containers with the same scroll direction. The view recycling only works when the height is set to MATCH_PARENT.
Depending on the complexity of the content inside of the NestedScrollView and the anticipated amount of RecyclerView items:
Ignore the problem. If there are only a few simple items, you may
not need view recycling at all.
When I hit the problem, I analysed the layouts of other popular apps: For example, WhatsApp only uses RecyclerViews (or ListViews with view recycling) in some parts of their app.
Particularly, this group settings screen with hundreds of possible items is made of multiple ListViews wrapped by a ScrollView, without any view recycling.
Replace the NestedScrollView with a single
ReyclerView with multiple item types and put all of your scrollable content inside of it. This is the way to go if you need view recycling.
Beware that you also have to convert all the other content in the NestedScrollView (headers and footers, spacing) to RecyclerView items with their own ViewHolders.
If the setup is rather simple, I would recommend you to implement it without additional libraries, following the link above.
There are a few different libraries available to solve your problem (all of them follow the second approach with a single RecyclerView), but most come with a lot of extra features which you may not need:
RendererRecyclerViewAdapter
It comes with a ViewRenderer/ViewModel interface, which works like a
"partial" RecyclerView for a single item type. You would create one
for every item type and then register them in a single adapter.
Epoxy
A library/framework create by airbnb and used heavily in their app.
They have a lot of scrollable content (similar to a web page) with a
lot of different item types. Epoxy also helps with the composition of
the different items on a page, and it handles animations when the
content or its order changes. Too much if you only need it for a single screen.
Litho
A complete UI framework created by Facebook which comes with it's own rendering engine, a replacement for xml layouts and much more. As far as I understand, it allows you to do to handle large amounts of items (like the Facebook timeline) and the view recycling is handled automatically. Like Epoxy, you would only use this if your app includes things like endless scrolling with a lot of different item types and you really need the performance.
I tried Epoxy and RendererRecyclerViewAdapter, but after all I created my own multiple item type adapter. It can be created in less than 100 lines of code.
Starting from RecyclerView:1.2.0-alpha04 we can use ConcatAdapter to solve this problem
https://developer.android.com/reference/androidx/recyclerview/widget/ConcatAdapter
I tried your problem by adding 20 items in each recyclerview, with NestedScrollView application called onBindViewHolder method 40 times. As you disabling nested scrolling in Java code i suggest to use Scrollview. By using ScrollView application called onBindViewHolder 33 times.
If you fix your recyclerView's height to specific size instead of "match-parent" it will reduce call to onBindViewHolder greatly.
<ScrollView 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:fillViewport="false">
<android.support.v7.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.vishal.my2.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/featured_list"
android:layout_width="match_parent"
android:layout_height="300dp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/all_topic_list"
android:layout_width="match_parent"
android:layout_height="300dp" />
</android.support.v7.widget.LinearLayoutCompat>
</ScrollView>
If Specifying hardcoded value to recyclerView's height does not meet your application requirement then you can try using ListView instead of recyclerView. pardon me if i am wrong, This was my first time answering any question.
Add this to nested scroll view android:fillViewport="false"

ListView nested scrolling on API<21

Title is clear. I'm having this layout:
_________________
|_______________| <- Toolbar
|___|___|___|___| <- Tablayout
| |
| |
| ViewPager |
| |
|_______________|
Both toolbar and tablayout are inside an AppBarLayout, so I can use scroll flags to hide the toolbar on scrolling toward the top. The problem is that this only works with nested-scrolling-supported views. Most of the tabs - I mean, most of the pages - are support.v4.NestedScrollViews, so that is OK; others are (and need to be) ListViews.
From Lollipop on, I can simply add android:nestedScrollingEnabled="true" to the list view, and the toolbar hides correctly on scroll.
On API<21, though, there's no such attribute and the toolbar doesn't hide. Even more important, the very last items in the list are hidden, because of some measuring bug in CoordinatorLayout: listview acts as if it had the space currently occupied by the toolbar.
Solutions:
Switch to RecyclerView, which does support nested scrolling: I can't, because I need to use an external-library adapter that works only with adapter views and that I can't replace (namely, ParseQueryAdapter);
Extend ListView and implement nested scrolling: seems way to complicated;
Extend ListView and implement some workaround, like measuring stuff to avoid the last-item issue or (and) a custom behavior to make the toolbar hide: seems complicated too;
Use some layout trick: found none.
Any help?
For example, I (desperately) tried:
<android.support.v4.widget.NestedScrollView
android:nestedScrollingEnabled="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</android.support.v4.widget.NestedScrollView>
But this way the ListView is not laid out as match_parent. I get a little view with small height, and the rest of the page is empty.
Unfortunately, there is no way to get nested scrolling working on ListView - otherwise it wouldn't require the modifications that were done in API 21.
You'll note that the current Parse SDK has actually removed ParseQueryAdapter entirely. Given that, it may make sense to start building your own RecyclerView based adapter using the Parse query APIs directly.
For those intersted in the specific ParseQueryAdapter issue,
Guys at parse.com are working on a RecyclerView.Adapter version;
There's a beta version of it.

How to create material design like custom scrollbar with numbers and alphabets bubble in recyclerview

In many new android applications and their latest update those applications(mostly material design) have a custom scrollbar with letters and numbers, while scrolling the scrollbar with thumb, alphabets or numbers appear beside thumb.I have attached screenshot to the question of the scrollbar from the application 'Contacts'.
Screenshot:
So, How to modify a scrollbar in my application which is using recyclerview, to create scrollbar like that scrollbar with the alphabet and number bubble or is there any new API or library introduced for that?
For anyone still looking for an answer for this. I have found a number of libraries which provide this functionality:
https://github.com/krimin-killr21/MaterialScrollBar
https://github.com/plusCubed/recycler-fast-scroll
https://github.com/danoz73/RecyclerViewFastScroller
https://github.com/timusus/RecyclerView-FastScroll
All of the above provide FastScroll mechanism (what you're looking for) - though some look nicer than others.
I have found the MaterialScrollBar easiest to get set with up and use, as well as the fact that it has the nicest cosmetics (adheres to material design guidelines and looks just like Contacts app).
This library is also actively maintained and developed, issues & PR's being closed etc.
Hope this may help someone as I spent a lot of time looking for this myself.
I use this new one now -
https://github.com/L4Digital/FastScroll
Below is my previous one.
I have used fastscroller by FutureMind in Android Studio
https://github.com/FutureMind/recycler-fast-scroll
Usage
1) Compile required dependency by adding
compile 'com.futuremind.recyclerfastscroll:fastscroll:0.2.4'
2) Edit Layout File to add FastScroller
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.futuremind.recyclerviewfastscroll.FastScroller
android:id="#+id/fastscroll"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"/>
</RelativeLayout>
3) In Activity/Fragment associate fastScroller with your recycler view
recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
fastScroller = (FastScroller) findViewById(R.id.fastscroll);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
//has to be called AFTER RecyclerView.setAdapter()
fastScroller.setRecyclerView(recyclerView);
4) In your RecyclerView.Adapter implement SectionTitleProvider to display the content on Bubble
public class MyAdapter ... implements SectionTitleProvider{
...
#Override
public String getSectionTitle(int position) {
//this String will be shown in a bubble for specified position
return getItem(position).substring(0, 1);
}
}
List View Variants library seems to be perfect for your needs, try it out.
Check out the demo below.
This library works fine and it is easy to use - Material Scroll Bar
It has also support for custom font.

Android, appcompat v21, implement scrolling techniques

In http://www.google.com/design/spec/patterns/scrolling-techniques.html described scrolling techniques.
But I have not found details of how to implement it.
I'm trying to implement "Flexible space with image" anyone have an example of this?
I think this lib perfectly suits your need :
https://github.com/ksoichiro/Android-ObservableScrollView
It includes all the scrolling techniques described in the Google design specs and more.
Moreover, it brings support for ListViews, GridViews, ScrollViews, RecyclerViews and WebViews.
I think this blog post has what you're looking for. It offers a guide to make a layout similar to that (although you might have to add some code to color the app bar).
The grand idea behind this sort of "layout trick" is to implement a ScrollView with some sort of onScrollChanged listener. The aim is to make your Activity aware of scroll changes and then could transform the required elements.
Once you could get a sense of the scroll position (and changes) you could use that value as a base to apply color transformation (for the ActionBar's background) and to rescale the header text.
Hope this helps.
Late but not least,
You need to you use Android Support Design Library v22 or Above. Specifically CoordinatorLayout with AppBar Layout and Toolbar.
<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">
<! -- Your Scrollable View -->
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
...
app:layout_scrollFlags="scroll|enterAlways">
<android.support.design.widget.TabLayout
...
app:layout_scrollFlags="scroll|enterAlways">
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
as mentioned in android Developer Blogpost
also described in Video by Ian Lake

vertical DrawerLayout or SlidingPaneLayout

The latest Android Support Library introduced the DrawerLayout to implement the common UX pattern where you slide right or left to show a navigation menu.
What I'd love to have is a vertical DrawerLayout with the same API, that can be pulled down/up from the top/bottom of my layout.
Since 4.2 the old SlidingDrawer has been deprecated and I haven't heard about some new Widget that implements the same functionality.
Can the DrawerLayout be extended somehow to implement the vertical swipe UX pattern?
Does google provide some different widget to implement it?
Google Music for instance has something very similar to what I'm looking to implement to pull up the player.
We have recently implemented this in the Umano App and open sourced: https://github.com/umano/AndroidSlidingUpPanel
Enjoy.
The Android support library now has the bottom sheets behavior to do that.
Check out this link for more info https://material.google.com/components/bottom-sheets.html
Nowadays, it makes more sense to use the BottomSheetBehavior that you can find more information on how setting it up on https://code.tutsplus.com/articles/how-to-use-bottom-sheets-with-the-design-support-library--cms-26031
Basically, you need to set your main content, and your sliding content. The BottomSheetBehavior would only work for panels that you slide from the bottom to the top.
It has a quite simple set up and the BottomSheetBehavior could even work out of the box. Only by writing a android.support.design.widget.CoordinatorLayout layout, with another View inside (with even wrap_content as a value in the layout_height parameter), for instance a LinearLayout like this one:
<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"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:behavior_hideable="true"
app:behavior_peekHeight="56dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<!-- Your content goes here -->
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
In my case, I inflate this layout in a Fragment and add it to the Activity where you want to enable the SlidingSheetBehavior.

Categories

Resources