SwipeRefreshLayout does not allow me to scroll up [duplicate] - android

This question already has answers here:
When I am scrolling up SwipeRefreshLayout refreshing my app
(4 answers)
Closed 3 years ago.
I have an app with a SwipeRefreshLayout which has a ListView inside it. When the ListView is populated, I can easily scroll down to read the older items on the list, but when I try to scroll up this action is mistaken for a Pull2Refresh action even though I am trying to scroll up. It does not matter where I position my finger it still mistakes this for a Pull2Refresh action. How can I sort this problem as scrolling back to the top is a problem.Here is the XML to that fragment with the SwipeRefreshLayout :
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipe_refresh_layout_general"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout 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"
tools:context="com.inc.automata.unamupdates.fragments.GeneralNewsFragment">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listViewGeneral">
</ListView>
</FrameLayout>
</android.support.v4.widget.SwipeRefreshLayout>

The problem is that you have wrapped your whole layout with the swipe refresh layout. You should only wrap your ListView with the SwipeRefreshLayout.
Link to original answer
<android.support.v4.widget.SwipeRefreshLayout
...
>
<RecyclerView
...
/>
</android.support.v4.widget.SwipeRefreshLayout>

try to Use follwoing attributes in listview
<FrameLayout 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"
tools:context="com.inc.automata.unamupdates.fragments.GeneralNewsFragment">
<ListView
android:id="#+id/listViewGeneral"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:smoothScrollbar="true"
android:fadeScrollbars="true"></ListView>
</FrameLayout>

Related

Android RecyclerView scrollbar doesn't work

the scrollbar in my RecyclerView doesn't work, I mean I can scroll the RecyclerView with touch, I also can see the scrollbar but it's can not move
Before ask the question I also tried with some answers here for example:
https://www.dev2qa.com/android-recyclerview-horizontal-scroll-example/
Android RecyclerView Scroll not working after Layout edit
But none of them work for me
Below is my code, thanks in advance
Layout file:
<?xml version="1.0" encoding="utf-8"?>
<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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HexViewActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_hex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadeScrollbars="false"
android:scrollbarSize="15dp"
android:scrollbars="vertical" />
</ScrollView>
Code to create the view
RecyclerView recyclerView = findViewById(R.id.rv_hex);
recyclerView.setLayoutManager(new LinearLayoutManager(HexConstant.app_ontext));
m_fileDataAdapter = new FileDataAdapter(HexConstant.app_ontext, files[0]);
recyclerView.setAdapter(m_fileDataAdapter);
recyclerView.setNestedScrollingEnabled(true);
Is there any example for Scrollbar + recyclerView, pls let me know
Change the outer layout with scroll view layout.
<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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HexViewActivity">
<!-- Your stuff here -->
</ScrollView>
Have you tried using RecyclerView's attribute app:fastScrollEnabled="true"?
Check the full answer here. https://stackoverflow.com/a/46026362/6455501

WebView inside RecyclerView, scrolling issue

I have a problem with webView with is in RecyclerView item.
After click on YouTube video or twitter post, WebView is scrolled to top.
here is my layout of WebView item:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true">
<WebView
android:id="#+id/postDetailItemWebView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
and here is a layout of Activity where recycler is displaying:
<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:animateLayoutChanges="true">
<android.support.design.widget.AppBarLayout ..../>
<android.support.v7.widget.RecyclerView
android:id="#+id/postDetailRecycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never"
android:layoutAnimation="#anim/linear_recycler_anim"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
<RelativeLayout..../>
WebView content is huge and it is more than screen size, that is why it needs scrolling. I have placed it inside RecyclerView becouse I have other items like: header and footer. Is there any fix for that or I have to place WebView outside RecyclerView as full screen view?
I had the same issue with im.delight.android.webview.AdvancedWebView. And I found a solution eventually.
This options helped me:
isFocusable = false
isFocusableInTouchMode = false
I hope they'll help you too.
WebViews support scrolling and shouldn't be places inside RecyclerView, try getting the WebView outside your RecyclerView

Enable intertial scroll in NestedScrollView (Android Studio)

I have a NestedScrollView (part of the default Scrolling Activity) that contains a CoordinatorLayout and RecyclerView to display cards with some information. The layout is designed to allow the cards to go off-screen if there are too many and have the user scroll down to them, however for some reason the scroll does not have momentum to it as it should. I looked around and a previous question told how to disable the intertial scroll in a ScrollView (Android ScrollView disable Inertial scrolling), so I tried to do the opposite:
NestedScrollView mgScrollView = (NestedScrollView) findViewById(R.id.my_games_scroll_view);
mgScrollView.setSmoothScrollingEnabled(true);
But this didn't accomplish it. I tested mgScrollView.setVerticalScrollBarEnabled(true); to see if I was even applying the code to the right view, and so it happens the scrollbars didn't show up either. So now I'm confused as to whether I'm even applying those methods to the right view, but since I don't have any other ScrollViews I'm not sure where it should be if I am incorrect. I know I can add scrollbars in the xml itself but I haven't found xml code for inertial scrolling. Is there a way to add inertia through Java or xml?
Here is the code for content_my_games.xml, which is where the layouts for the cards go (not to be confused with activity_my_games.xml, which houses code for the CollapsingToolbarLayout and FAB)
Thanks
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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/my_games_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.abhinav.sportswowandroid.MyGamesActivity"
tools:showIn="#layout/activity_my_games">
<RelativeLayout 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="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
tools:context=".MyGamesActivity">
<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=".MyGamesActivity"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"
/>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
Old question, but just ran into this myself. This solved it for me:
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setNestedScrollingEnabled(false);

SwipeRefreshLayout not allowing listview row item horizontal scrolling

I have viewPager inside that there is 2 Fragment. Inside fragment1.xml
<RelativeLayout 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"
android:background="#color/background_color"
android:focusable="false"> <android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listView_feed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animationCache="true"
android:clipToPadding="false"
android:divider="#color/transparent"
android:dividerHeight="2dp"
android:paddingBottom="12dp"
android:paddingTop="12dp"
android:scrollbars="none"
android:focusable="true"
android:scrollingCache="false"
android:smoothScrollbar="true" /></android.support.v4.widget.SwipeRefreshLayout></RelativeLayout>
And in listView_feed there is another horizontal_listview inside listView_feed each row but while adding inside SwipeRefreshLayout it will not allowing horizontal_listview horizontal scroll and focus moved to pager. But if I move listView_feed outside SwipeRefreshLayout then each listView_feed child can scroll horizontally.
Thank you who tried and see my question. Finally I found one good library by using it I was able to achieve my requirement. But it is not same as SwipeRefershLayout. It is refreshing in header not over Listview but it works great.

DrawerLayout Not Scrolling

I notice that the drawers within the Google applications are scrollable, but I cannot for some reason come to the conclusion of how to achieve a scrollable DrawerLayout. I attempted to construct the layout file with the following design paradigm.
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".mainScreen">
<!-- Layout of Activity -->
</FrameLayout>
<!-- DrawerLayout segment -->
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/drawerLinearLayout"
android:orientation="vertical"
android:layout_width="260dp"
android:layout_height="match_parent"
android:layout_gravity="start|bottom"
android:layout_marginTop="?android:attr/actionBarSize"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#77000000">
<!-- Layout of Drawer -->
</LinearLayout>
</ScrollView>
</android.support.v4.widget.DrawerLayout>
But, with or without the ScrollView, the drawer just cuts items off at the bottom when they go beyond the end of the screen. I can't get any form of scrolling enabled. Not sure what I am missing or need to enable. Thoughts would be appreciated.
The LinearLayout in the DrawerLayout segment contains different styled views. One view displays title only with a divider below it, one displays an imageview with text next to it and another displays a title with a switch built into the row. So, multiple styled views need to be accounted for if done outside of XML coded layout files.
While using a ListView is a valid option, it was useful for me to attempt and resolve the situation for which I already had such a large XML file constructed for my layout in between the ScrollView above. As it turned out, there were only a few small modifications needed in order to get it working as intended. The latest layout file constructed is the following:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".mainScreen">
<!-- Layout of Activity -->
</FrameLayout>
<!-- DrawerLayout segment -->
<ScrollView
android:id="#+id/scrollView"
android:layout_width="260dp"
android:layout_height="match_parent"
android:layout_gravity="start|bottom"
android:layout_marginTop="?android:attr/actionBarSize">
<LinearLayout
android:id="#+id/drawerLinearLayout"
android:orientation="vertical"
android:layout_width="260dp"
android:layout_height="wrap_content"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#77000000">
<!-- Layout of Drawer -->
</LinearLayout>
</ScrollView>
</android.support.v4.widget.DrawerLayout>
The main modifications required me to alter where the gravity and the margin existed. The gravity needed to be in the surrounding ScrollView otherwise it would cause odd behavior that didn't scroll or actually crashed in some instances apparently. Then the inner layout needed to be changed to 'wrap content'.
If the margin was not moved into the ScrollView as well, it apparently doesn't scroll down to the bottom. It left a margin of scroll unscrolled at the bottom. Once this was resolved, the DrawerLayout worked as was expected at this point. The ListView option also proposed is another approach to be used, but as mentioned at this point it was worth me analyzing it a bit further to re-use the code that I already had written; especially with several different custom views that would need to be handled inside the view.
It seems that it only works properly with a ListView. You will take less time to migrate to ListView than trying to make the ScrollView to work.
You should use a listview along with the frame layout. Something like this :
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"/>
<ListView android:id="#+id/left_drawer"
android:layout_width="180dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
You can also refer to the Navigation Drawer documentation at developer.android.com. It has everything you will need.

Categories

Resources