Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to scroll pull to refresh scrollview in normal scrollview

Here is my layout xml.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/garae_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:fillViewport="true"
android:focusableInTouchMode="false" >
   <RelativeLayout>
      ...
      <com.handmark.pulltorefresh.library.PullToRefreshScrollView>
         <LinearLayout/>
      </com.handmark.pulltorefresh.library.PullToRefreshScrollView>
   </RelativeLayout>
</ScrollView>

I already tried the solution in this link: ScrollView Inside ScrollView

However, it didn't work. How can do use child PullToRefreshScrollView?? Please help me.

like image 616
user3517556 Avatar asked Apr 10 '14 01:04

user3517556


People also ask

What is fillViewport in ScrollView?

android:fillViewport. Defines whether the scrollview should stretch its content to fill the viewport.

What is the difference between ScrollView and horizontal ScrollView?

Attributes Of Scroll View: ScrollView and HorizontalScrollView has same attributes, the only difference is scrollView scroll the child items in vertical direction while horizontal scroll view scroll the child items in horizontal direction.

Can ScrollView be horizontal?

Horizontal ScrollView is a FrameLayout, used to provide the child View element horizontal scrolling property. The ChildView in itself can be a layout manager like the linear layout. The TextView class takes care of its own scrolling, But it can be placed inside a HorizontalScrollView to create more complex UI designs.


1 Answers

If I understand your question, you want to implement a Pull to refresh in your Scrollview. Instead, to use the library you are using, I would suggest you to implement a SwipeRefreshLayout https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html It is a layout that implements a pull-to-refresh like in the application of Google+ or Gmail.

Here's an example implementing SwipeRefreshLayout in your xml:

    <?xml version="1.0" encoding="utf-8"?>

    <FrameLayout
        android:layout_width="match_parent" android:layout_height="match_parent"
        xmlns:android="http://schemas.android.com/apk/res/android" >

        <android.support.v4.widget.SwipeRefreshLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/swipe_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

          <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:tools="http://schemas.android.com/tools"
             android:id="@+id/garae_scroll"
             android:layout_width="match_parent"
             android:layout_height="wrap_content" >

         </ScrollView>

       </android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>

NOTE

It is highly not recommended to put a Scrollview/Listview inside a Scrollview/Listview. The first reason is about the performance and Romain Guy explains that in one video https://www.youtube.com/watch?v=wDBM6wVEO70

like image 111
Hugo Avatar answered Oct 13 '22 21:10

Hugo