如何在AndroidStudio中使用拉起刷新时的滚动视图?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (90)

有以下代码:

<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();

            }
        });

​有什么办法解决吗?

提问于
用户回答回答于

若要实现在列表顶部工作的拉到刷新行为,可用以下代码:

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

扫码关注云+社区

领取腾讯云代金券