代码之家  ›  专栏  ›  技术社区  ›  Faisal Abid

以编程方式抛出listview android

  •  5
  • Faisal Abid  · 技术社区  · 15 年前

    有没有一种方法可以编程地在ListView上执行Fling?我知道有一只猴子可以做所有这些事情,但它需要与ADB等的计算机连接。我想用我的应用程序在任何电话上做,而不是猴子。

    谢谢, 费萨尔

    3 回复  |  直到 13 年前
        1
  •  -1
  •   Lucas S.    15 年前

    你可以用一个动画来伪装它(我认为加速减速插补器可以做到这一点)。

    此外,似乎还支持按自己的视图滚动:

    public void scrollBy (int x, int y)
    

    移动视图的滚动位置。这将导致调用onscrollchanged(int,int,int,int),视图将失效。

    Parameters
    x   the amount of pixels to scroll by horizontally
    y   the amount of pixels to scroll by vertically
    
    public void scrollTo (int x, int y)
    

    设置视图的滚动位置。这将导致调用onscrollchanged(int,int,int,int),视图将失效。

    Parameters
    x   the x position to scroll to
    y   the y position to scroll to
    
        2
  •  2
  •   Matt Briançon    14 年前

    有两种方法可以“平滑滚动”而不是跳转到某个位置。

    退房 http://developer.android.com/reference/android/widget/ScrollView.html

    对于 smoothScrollBy() smoothScrollTo() .

    希望这有帮助。

        3
  •  1
  •   itsadok    13 年前
    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);
    
    }