有很多类似的问题,但我的问题有点不同。向下滚动时,Activity工作得很好。然而,当我向上滚动时,它不是滚动,而是刷新。我实际上想要的是,只有当我在嵌套滚动视图的顶部时,它才会刷新。我必须快速双击,这样我才能向上滚动,这有点困难。
截图:
Details.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
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:id="@+id/swipe_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".details">
<android.support.design.circularreveal.
coordinatorlayout.CircularRevealCoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing"
android:layout_width="match_parent"
android:layout_height="350dp"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="#0e0d0e"
app:expandedTitleTextAppearance="@android:color/transparent"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/img_beach"
android:contentDescription="@null"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:title="Beach Name"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="parallax"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/btnSubmit"
android:src="@drawable/send"
android:backgroundTint="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:elevation="6dp"
app:layout_anchor="@id/app_bar_layout"
app:layout_anchorGravity="bottom|right|end"
app:pressedTranslationZ="12dp"
app:useCompatPadding="true"
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/btn_rating"
android:src="@drawable/ic_add_black_24dp"
android:backgroundTint="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:elevation="6dp"
app:layout_anchor="@id/app_bar_layout"
app:layout_anchorGravity="bottom|right|start"
app:pressedTranslationZ="12dp"
app:useCompatPadding="true"
/>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="5dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/beach_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:padding="12dp"
android:text="Food Name"
android:textColor="@color/colorPrimary"
android:textSize="20sp"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/layout_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/money" />
<TextView
android:id="@+id/beach_price"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="9"
android:text="1,000"
android:textColor="@color/colorPrimary"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<com.cepheuen.elegantnumberbutton.view.ElegantNumberButton
android:id="@+id/number_button"
android:layout_width="100dp"
android:layout_height="30dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="10dp"
app:backGroundColor="@color/number_button"
app:finalNumber="20"
app:initialNumber="1"
app:textSize="8sp" />
<LinearLayout
android:id="@+id/layout_checkDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:id="@+id/checkInBTN"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="CHECK IN"
android:textSize="12sp" />
<TextView
android:id="@+id/checkInTV"
android:layout_width="90dp"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:layout_marginTop="6dp"
android:layout_marginBottom="10dp"
android:gravity="center_vertical"
android:text="CHECK IN DATE"
android:textAlignment="center" />
<Button
android:id="@+id/checkOutBTN"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="CHECK OUT"
android:textSize="12sp" />
<TextView
android:id="@+id/checkOutTV"
android:layout_width="90dp"
android:layout_height="match_parent"
android:layout_marginLeft="8dp"
android:layout_marginTop="6dp"
android:layout_marginBottom="10dp"
android:gravity="center_vertical"
android:text="CHECK OUT DATE"
android:textAlignment="center" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_checkAvailability"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:id="@+id/checkAvailabilityBTN"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:gravity="center|center_horizontal"
android:text="CHECK AVAILABILITY"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="5dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RatingBar
android:id="@+id/rating_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:isIndicator="true"
android:max="5"
android:rating="0" />
<TextView
android:id="@+id/beach_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:lineSpacingMultiplier="1.5"
android:padding="12dp"
android:text="Description"
android:textColor="@android:color/black"
android:textSize="14sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="5dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/beach_review"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:lineSpacingMultiplier="1.5"
android:padding="12dp"
android:text="REVIEWS"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold|italic" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerComment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="12dp"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/beach_gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:lineSpacingMultiplier="1.5"
android:padding="12dp"
android:text="GALLERY"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold|italic" />
<ImageView
android:id="@+id/img_beach2"
android:layout_width="match_parent"
android:layout_height="250dp"
android:scaleType="centerCrop"
android:src="@drawable/background" />
<ImageView
android:id="@+id/img_beach3"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_marginTop="20dp"
android:scaleType="centerCrop"
android:src="@drawable/background" />
<ImageView
android:id="@+id/img_beach4"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_marginTop="20dp"
android:scaleType="centerCrop"
android:src="@drawable/background" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.circularreveal.
coordinatorlayout.CircularRevealCoordinatorLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Details.java
mSwipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
mSwipeRefreshLayout.setRefreshing(true);
if(!menuID.isEmpty() && menuID != null){
Query query = ratingTbl.orderByChild("menuID").equalTo(menuID);
FirebaseRecyclerOptions<Rating> options = new FirebaseRecyclerOptions.Builder<Rating>()
.setQuery(query, Rating.class)
.build();
adapter = new FirebaseRecyclerAdapter<Rating, ShowCommentViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull ShowCommentViewHolder holder, int position, @NonNull Rating model) {
holder.ratingBar.setRating(Float.parseFloat(model.getRateValue()));
holder.txtComment.setText(model.getComment());
holder.txtUserEmail.setText(model.getUserEmail());
}
@NonNull
@Override
public ShowCommentViewHolder onCreateViewHolder(ViewGroup parent, int i) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.show_comment_layout, parent, false);
return new ShowCommentViewHolder(view);
}
};
loadComment(menuID);
}
}
});
mSwipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
mSwipeRefreshLayout.setRefreshing(true);
if(!menuID.isEmpty() && menuID != null){
Query query = ratingTbl.orderByChild("menuID").equalTo(menuID);
FirebaseRecyclerOptions<Rating> options = new FirebaseRecyclerOptions.Builder<Rating>()
.setQuery(query, Rating.class)
.build();
adapter = new FirebaseRecyclerAdapter<Rating, ShowCommentViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull ShowCommentViewHolder holder, int position, @NonNull Rating model) {
holder.ratingBar.setRating(Float.parseFloat(model.getRateValue()));
holder.txtComment.setText(model.getComment());
holder.txtUserEmail.setText(model.getUserEmail());
}
@NonNull
@Override
public ShowCommentViewHolder onCreateViewHolder(ViewGroup parent, int i) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.show_comment_layout, parent, false);
return new ShowCommentViewHolder(view);
}
};
loadComment(menuID);
}
}
});
5条答案
按热度按时间uhry853o1#
如果
RecyclerView
或ListView
不是SwipeRefreshLayout
的直接子项,则会出现此问题。最简单的解决方案是提供
OnChildScrollUpCallback
实现并适当地返回结果。在下面的Kotlin代码中,refreshLayout
是SwipeRefreshLayout
,recyclerView
是RecyclerView
,这在xml
布局代码中也可以看到。虽然
xml
的布局是这样的,p1iqtdky2#
是否尝试使用NestedScrollView Package SwipeRefreshLayout?
对我有效:
14ifxucb3#
我是这样解决的
x4shl7ld4#
我在
ScrollView
上添加了OnScrollChangeListener
,以根据滚动条的位置启用/禁用SwipeRefreshLayout
。我仅在scrollY位于顶部时启用滑动刷新,并且它不会妨碍我的scrollView。Kotlin中的代码看起来像这样:
ldxq2e6h5#
我已经修复了它,把滑动刷新布局内的协调器布局。非常感谢所有观众:)