问题
I have the following layout
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
//some views here
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="*" >
</TableLayout>
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
The problem is when I scrolldown the table, I can't scrollUp again because the swipelayout is being triggered. How can I trigger the swiperefresh only when the first view of the table is visible?
回答1:
I found that if you replace your ScrollView with a android.support.v4.widget.NestedScrollView the scrolling behavior will work as you expect it to.
回答2:
Make your own implementation of SwipeRefreshLayout and override the canChildScrollUp in this way:
@Override
public boolean canChildScrollUp() {
if (scrollView != null)
return scrollView.canScrollVertically(-1);
return false;
}
just replace with any subclass of ScrollView.
回答3:
If you have layout like this:
<SwipeRefreshLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/your_scroll_view_id">
<LinearLayout>
...
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</SwipeRefreshLayout>
You need to create your own class and override the function in this way:
class SwipeRefreshLayoutCustom extends SwipeRefreshLayout {
public SwipeRefreshLayoutCustom(Context context, AttributeSet attributes) {
super(context, attributes)
}
@override
boolean canChildScrollUp() {
return your_scroll_view_id.scrollY != 0
}
}
回答4:
Use NestedScrollView with:
app:layout_behavior="@string/appbar_scrolling_view_behavior"
来源:https://stackoverflow.com/questions/25294395/swiperefreshlayout-with-scrollview-and-layout-above