有没有一种方法可以通过编程在listview上执行Fling操作?我知道有一个名为monkey的工具可以完成所有这些操作,但需要使用adb等计算机连接。我想在任何手机上使用我的应用程序进行操作,而不是使用monkey。
谢谢, Faisal
有两种方法可以实现“平滑滚动”,而不是跳转到某个位置。
请查看http://developer.android.com/reference/android/widget/ScrollView.html,了解smoothScrollBy()
和smoothScrollTo()
的用法。
希望这可以帮到你。
private AnimationSet set;
public void onClick(View v) {
if(v.getId() == R.id.pullbutton){
artListview.setVisibility(View.INVISIBLE);
if(set == null){
set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(100);
set.addAnimation(animation);
animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, -1.0f,
Animation.RELATIVE_TO_SELF, 0.0f
);
animation.setDuration(1000);
set.addAnimation(animation);
}
showPullDownSectionList();
}
}
public void showPullDownSectionList() {
flipper = (ViewFlipper) findViewById(R.id.ViewFlipper01);
flipper.setVisibility(View.VISIBLE);
setLayoutAnim_slidedownfromtop(flipper);
}
public void setLayoutAnim_slidedownfromtop(ViewFlipper flipper) {
LayoutAnimationController controller =
new LayoutAnimationController(set, 0.25f);
flipper.setLayoutAnimation(controller);
}
你可以使用动画来模拟它(我认为加速减速插值器可以完成这项工作)。
此外,似乎也支持通过自己的方式滚动视图:
public void scrollBy (int x, int y)
移动你的视图的滚动位置。这将导致调用 onScrollChanged(int, int, int, int) 并且视图将被无效化。
参数 x 要水平滚动的像素数 y 要垂直滚动的像素数
public void scrollTo (int x, int y)
设置视图的滚动位置。这将导致调用 onScrollChanged(int, int, int, int) 并使视图无效。
参数 x 要滚动到的 x 位置 y 要滚动到的 y 位置