java - Android Studio 中的 ScrollView,同时使用上拉刷新

标签 java android

所以我有一个刷新向下滑动功能,当你从屏幕上的任何地方下拉时它会刷新...但是我不想要这个,我有一个 ListView ,它是由 JSon 对象泵送的..this部分并不重要,我让所有的 json 都工作了...我不明白的部分是如何制作它,所以当我拉起 ListView 时,我会进入 ListView ,现在当我拉起时整个页面刷新。 我该页面的 XML ...

<in.srain.cube.views.ptr.PtrClassicFrameLayout
    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:id="@+id/ptr_care"
    >

    <android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.fzhang.nhchecklist.ResidentCareActivity">


        <TextView
            android:id="@+id/care_summary_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20sp"
            android:textColor="@android:color/black"
            tools:layout_constraintTop_creator="1"
            android:layout_marginStart="2dp"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="20dp"
            tools:layout_constraintLeft_creator="1"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginLeft="2dp" />


        <ListView
            android:id="@+id/care_info_listview"
            android:fadeScrollbars="false"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="0dp"
            android:layout_marginRight="0dp"
            android:layout_marginTop="10dp"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/care_summary_textview" />


    </android.support.constraint.ConstraintLayout>


</in.srain.cube.views.ptr.PtrClassicFrameLayout>

我的java

  mPtrFrame=(PtrClassicFrameLayout)findViewById(R.id.ptr_care);
        mPtrFrame.setLastUpdateTimeRelateObject(this);
        mPtrFrame.setPtrHandler(new PtrHandler() {
            @Override
            public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
                return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header);
            }

            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
                updateDataWithPTR();

            }
        });

任何人有任何好的想法,还有刷新和onResume...虽然这并不重要(如果确实请纠正我)感谢您的帮助

最佳答案

要实现在列表顶部起作用(当您在 care_summary_textview 上执行拉动手势时起作用)而不是在列表本身上起作用的拉动刷新行为,请使用以下命令:

<android.support.constraint.ConstraintLayout
    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"
    tools:context="com.fzhang.nhchecklist.ResidentCareActivity">

   <in.srain.cube.views.ptr.PtrClassicFrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/ptr_care"
        tools:layout_constraintTop_creator="1"
        android:layout_marginStart="2dp"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="20dp"
        tools:layout_constraintLeft_creator="1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginLeft="2dp">

       <TextView
           android:id="@+id/care_summary_textview"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:textSize="20sp"
           android:textColor="@android:color/black"/>

   </in.srain.cube.views.ptr.PtrClassicFrameLayout>

    <ListView
        android:id="@+id/care_info_listview"
        android:fadeScrollbars="false"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="0dp"
        android:layout_marginRight="0dp"
        android:layout_marginTop="10dp"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/ptr_care" />


</android.support.constraint.ConstraintLayout>

关于java - Android Studio 中的 ScrollView,同时使用上拉刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50865156/

相关文章:

java - 如何使用spring boot在java中运行neo4j查询?

java - 为什么在 eclipse 中出现 NoClassDefFound 错误是可以接受的?解决办法是什么?

android - 如何将android meminfo转储到文件中?

android - Android Lollipop 上的持久化应用程序

android - 根据存储在 SQLite 数据库中的位置(纬度和经度)和时间计算速度

java - 将数据显示到 RecyclerView 中

java - Azure 移动服务异步任务

ADLS Gen2 中文件的 Java 文件对象

android - 从android图库获取图像并放入gridview

java - 无法加载类 'com.intellij.util.Consumer'