如何滚动拉动以刷新普通滚动视图中的滚动视图

问题描述 投票:2回答:1

这是我的布局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>

我已经在此链接中尝试过该解决方案:ScrollView Inside ScrollView

但是,它没有用。如何使用子项PullToRefreshScrollView?请帮助我。

android layout refresh scrollview pull
1个回答
9
投票

如果我理解您的问题,您想在滚动视图中实现拉动以刷新。相反,要使用您正在使用的库,建议您实现SwipeRefreshLayouthttps://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html它是一种布局,可以像Google+或Gmail的应用程序一样实现一键式刷新。

这是在您的xml中实现SwipeRefreshLayout的示例:

    <?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

强烈建议不要在滚动视图/列表视图中放置滚动视图/列表视图。第一个原因与性能有关,罗曼·盖伊(Romain Guy)解释说,在一个视频中https://www.youtube.com/watch?v=wDBM6wVEO70

© www.soinside.com 2019 - 2024. All rights reserved.