!
.
:
<MultiSwipeRefreshLayout>
<LinearLayout>
<RelativeLayout>
<ListView @+id/list_1 />
<TextView @+id/list_1_empty_view />
</RelativeLayout>
<RelativeLayout>
<ListView @+id/list_2 />
<TextView @+id/list_2_empty_view />
</RelativeLayout>
</LinearLayout>
</MultiSwipeRefreshLayout>
: https://developer.android.com/samples/SwipeRefreshMultipleViews/index.html
, SwipeRefreshLayout .
1) -, MultiSwipeRefreshLayout.java, modificine, , SwipeRefreshLayout;
2) -, SwipeRefreshLayout.java MultiSwipeRefreshLayout.java :
private View[] mSwipeableChildren;
private boolean canChildScrollUp = true;
public void setSwipeableChildren(final int... ids) {
assert ids != null;
mSwipeableChildren = new View[ids.length];
for (int i = 0; i < ids.length; i++) {
mSwipeableChildren[i] = findViewById(ids[i]);
}
}
public boolean canChildScrollUp(MotionEvent ev) {
if (mSwipeableChildren != null && mSwipeableChildren.length > 0
&& ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
View target = null;
for (View view : mSwipeableChildren) {
if (view != null && view.isShown() && isInViewRect(ev, view)) {
target = view;
}
}
if (target != null && canViewScrollUp(target) ) {
canChildScrollUp = true;
}else{
canChildScrollUp = false;
}
}
return canChildScrollUp;
}
private static boolean isInViewRect(MotionEvent ev, View view){
int location[] = new int[2];
view.getLocationOnScreen(location);
RectF viewRectF = new RectF(
location[0], location[1],
location[0]+view.getWidth(), location[1] + view.getHeight()
);
float xOnScreen = ev.getRawX();
float yOnScreen = ev.getRawY();
return viewRectF.contains(xOnScreen, yOnScreen);
}
private static boolean canViewScrollUp(View view) {
if (android.os.Build.VERSION.SDK_INT >= 14) {
return ViewCompat.canScrollVertically(view, -1);
} else {
if (view instanceof AbsListView) {
final AbsListView listView = (AbsListView) view;
return listView.getChildCount() > 0 &&
(listView.getFirstVisiblePosition() > 0
|| listView.getChildAt(0).getTop() < listView.getPaddingTop());
} else {
return view.getScrollY() > 0;
}
}
}
: canChildScrollUp() → > canChildScrollUp (MotionEvent ev),
: canChildScrollUp. - google sammple refrence.
, ListView ScrollView TextView . , ListView SwipeRefreshLayout.
, .