0
我想滚动到特定项目,具体取决于用户点击的位置。我所有的列表视图都是不同的高度。请看下面的图片。滚动ListView到点击坐标,如QQ
因此,如果在列表项1,用户点击允许假设,所以它的底部应该滚动,直到softkeyboard的顶部。
项目和键盘的高度各不相同。我已尝试getTop
,getHeight
,getMeasuredHeight
,但迄今没有任何工作。
我想滚动到特定项目,具体取决于用户点击的位置。我所有的列表视图都是不同的高度。请看下面的图片。滚动ListView到点击坐标,如QQ
因此,如果在列表项1,用户点击允许假设,所以它的底部应该滚动,直到softkeyboard的顶部。
项目和键盘的高度各不相同。我已尝试getTop
,getHeight
,getMeasuredHeight
,但迄今没有任何工作。
主要的一点是要找到点击UI,并在键盘顶部之间的距离。
这是距离公式。你可以用这个来实现你的功能。您需要
假设下面是你的ListView,正在单击
int[] loc = new int[2];
lvItem_button.getLocationOnScreen(loc);
放
以同样的方式获取它的坐标。
int[] cords= new int[2];
keyboard_top_layout.getLocationOnScreen(cords);
double distance = Math.sqrt(Math.pow((cords[0] - loc[0]), 2) + Math.pow((cords[1] - loc[1]), 2));
distance -= heightOfItem; //subtract height because we want to align bottom of item to top of keyboard
distance = Math.ceil(distance);
lvItem.smoothScrollBy((int) -distance, 500); //-distance because X is increasing at bottom and decreasing at top. 500 is delay in scrolling. so it's smooth scroll
全部完成:)
谢谢,这工作:) – 2014-11-05 02:45:07