以编程方式在Android中实现ListView的快速滚动

5

有没有一种方法可以通过编程在listview上执行Fling操作?我知道有一个名为monkey的工具可以完成所有这些操作,但需要使用adb等计算机连接。我想在任何手机上使用我的应用程序进行操作,而不是使用monkey。

谢谢, Faisal

3个回答

2

你提到了ScrollView,但问题是关于ListView的。ListView也有一些很棒的功能:smoothScrollToPosition和smoothScrollByOffset。然而,它们只在API级别8和11中才可用。http://developer.android.com/reference/android/widget/ListView.html#smoothScrollToPosition(int) - David Olsson

1
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);

}

-1

你可以使用动画来模拟它(我认为加速减速插值器可以完成这项工作)。

此外,似乎也支持通过自己的方式滚动视图:

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 位置

嘿,卢卡斯,你有代码片段吗?我很困惑。谢谢, 费萨尔 - Faisal Abid
1
你好,我添加了更多信息以帮助你。 - Lucas S.
3
这不起作用。它滚动包含ListView的视图,但不是实际的ListView...抱歉...还在寻找。 - EddieB

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接