Skip to content

Commit 8fa4167

Browse files
committed
增加一个用于解决ScrollView嵌套ListView/GridView/WebView/RecyclerView等无法置顶问题的方法
1 parent 047750f commit 8fa4167

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

utilcode/lib/src/main/java/com/blankj/utilcode/util/ViewUtils.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,28 @@ public static void setViewEnabled(View view, boolean enabled, View... excludes)
3333
}
3434
view.setEnabled(enabled);
3535
}
36+
37+
/**
38+
* 用于解决ScrollView嵌套ListView/GridView/WebView/RecyclerView等无法置顶问题
39+
*
40+
* @param view ScrollView嵌套的跟视图
41+
*/
42+
public static void fixScrollViewTopping(View view) {
43+
view.setFocusable(false);
44+
ViewGroup viewGroup = null;
45+
if (view instanceof ViewGroup) {
46+
viewGroup = (ViewGroup) view;
47+
}
48+
if (viewGroup == null) {
49+
return;
50+
}
51+
for (int i = 0, n = viewGroup.getChildCount(); i < n; i++) {
52+
View childAt = viewGroup.getChildAt(i);
53+
childAt.setFocusable(false);
54+
if (childAt instanceof ViewGroup) {
55+
fixScrollViewTopping(childAt);
56+
}
57+
}
58+
}
59+
3660
}

0 commit comments

Comments
 (0)