android - 如何在普通 ScrollView 中滚动拉动刷新 ScrollView

标签 android layout refresh scrollview pull

这是我的布局 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? 请帮助我。

最佳答案

如果我理解你的问题,你想在你的 ScrollView 中实现拉动刷新。相反,要使用您正在使用的库,我建议您实现 SwipeRefreshLayout https://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>

注意

强烈建议将 Scrollview/Listview 放入 Scrollview/Listview 中。第一个原因与性能有关,Romain Guy 在一个视频 https://www.youtube.com/watch?v=wDBM6wVEO70 中解释了这一点。

关于android - 如何在普通 ScrollView 中滚动拉动刷新 ScrollView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22976823/

相关文章:

android - 如何通过 ksoap2-android 将复杂类型发送到 wcf 服务? - 如何配置wcf 服务?

android - 带有计时器的android媒体播放器服务

android - 如何监控和获取 Android 应用程序中的 http 流量?

php - 从服务器端强制刷新客户端页面

php - 重定向页面不起作用,除非我先刷新它

mysql - 每当MYSQL数据库数据发生变化时,是否会调用任何事件?

java - 如何在一个方法中管理多个事件

android - 如何在android中点击相同框架布局中的两个重叠按钮

html - 等高元素,在 flexbox 容器内底部对齐,纯 CSS

Android textview 居中定位