ScrollView滚动到底部使用的scrollTo和fullScroll方法的异同
2017-05-27 10:12
274 查看
scrollTo和fullScroll两个方法经常被用来做滚动到底部的操作
不过就这个功能而言 也是有不同之处的
使用fullScroll滚动到底部 使用的参数为 FOCUS_DOWN 顾名思义 和 焦点有关
fullScroll 代码如下
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
可以看到 fullScroll将视图滚动到底部 同时焦点作出了改变
scrollTo方法 只执行移动至某位置 不对其他属性作出修改
因此 使用 fullScroll 来执行滚动到底部时 需注意 此时你的UI焦点已经发生变化 且 底部UI无法获得焦点时 此方法无效
不过就这个功能而言 也是有不同之处的
使用fullScroll滚动到底部 使用的参数为 FOCUS_DOWN 顾名思义 和 焦点有关
fullScroll 代码如下
/** * <p>Handles scrolling in response to a "home/end" shortcut press. This * method will scroll the view to the top or bottom and give the focus * to the topmost/bottommost component in the new visible area. If no * component is a good candidate for focus, this scrollview reclaims the * focus.</p> * * @param direction the scroll direction: {@link android.view.View#FOCUS_UP} * to go the top of the view or * {@link android.view.View#FOCUS_DOWN} to go the bottom * @return true if the key event is consumed by this method, false otherwise */ public boolean fullScroll(int direction) { boolean down = direction == View.FOCUS_DOWN; int height = getHeight(); mTempRect.top = 0; mTempRect.bottom = height; if (down) { int count = getChildCount(); if (count > 0) { View view = getChildAt(count - 1); mTempRect.bottom = view.getBottom() + mPaddingBottom; mTempRect.top = mTempRect.bottom - height; } } return scrollAndFocus(direction, mTempRect.top, mTempRect.bottom); } /** * <p>Scrolls the view to make the area defined by <code>top</code> and * <code>bottom</code> visible. This method attempts to give the focus * to a component visible in this area. If no component can be focused in * the new visible area, the focus is reclaimed by this ScrollView.</p> * * @param direction the scroll direction: {@link android.view.View#FOCUS_UP} * to go upward, {@link android.view.View#FOCUS_DOWN} to downward * @param top the top offset of the new area to be made visible * @param bottom the bottom offset of the new area to be made visible * @return true if the key event is consumed by this method, false otherwise */ private boolean scrollAndFocus(int direction, int top, int bottom) { boolean handled = true; int height = getHeight(); int containerTop = getScrollY(); int containerBottom = containerTop + height; boolean up = direction == View.FOCUS_UP; View newFocused = findFocusableViewInBounds(up, top, bottom); if (newFocused == null) { newFocused = this; } if (top >= containerTop && bottom <= containerBottom) { handled = false; } else { int delta = up ? (top - containerTop) : (bottom - containerBottom); doScrollY(delta); } if (newFocused != findFocus()) newFocused.requestFocus(direction); return handled; }1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
可以看到 fullScroll将视图滚动到底部 同时焦点作出了改变
scrollTo方法 只执行移动至某位置 不对其他属性作出修改
因此 使用 fullScroll 来执行滚动到底部时 需注意 此时你的UI焦点已经发生变化 且 底部UI无法获得焦点时 此方法无效
相关文章推荐
- ScrollView滚动到底部使用的scrollTo和fullScroll方法的异同
- 滚动到底部或顶部响应的ScrollView使用
- 界面为ScrollView时打开界面会自动滚动到底部之解决方法
- Android textview 不使用ScrollView也可滚动的方法
- 安卓控件使用系列22:ScrollView垂直滚动控件的使用方法
- Android垂直滚动控件ScrollView使用方法详解
- 界面为ScrollView时打开界面会自动滚动到底部之解决方法
- ScrollView的基础使用方法以及多图的循环滚动和缩放
- 界面为ScrollView时打开界面会自动滚动到底部之解决方法
- HorizontalScrollView水平滚动控件使用方法详解
- 界面为ScrollView时打开界面会自动滚动到底部之解决方法
- ScrollView无法完全滚动到底部解决方法
- 【iOS发展-53】实例探究:scrollView使用方法和解决方案无法滚动核心
- 解决ScrollView里如果有动态更新的ChildView时会自动滚动到底部的方法
- 滚动到底部或顶部响应的ScrollView使用
- Android中滑屏初探 ---- scrollTo 以及 scrollBy方法使用说明
- 使用Unity3D时,UIScrollView不滚动问题的解决方法
- Android中滑屏初探 ---- scrollTo 以及 scrollBy方法使用说明
- Android中滑屏初探 ---- scrollTo 以及 scrollBy方法使用说明
- 解决ScrollView滑动过程中ScrollTo()方法不起作用的问题