Programmatically Fling ListView Android

前端 未结 3 1330

Is there a way I can programatically perform a Fling on a listview? I know there is monkey that does all these things but that requires a computer connection with adb etc et

相关标签:
3条回答
  • 2021-01-01 02:50

    You can fake it with an anim (i think accelerate_decelerate_interpolator can do the job).

    Also it seems there is support for scrolling your view by your own:

    public void scrollBy (int x, int y)
    

    Move the scrolled position of your view. This will cause a call to onScrollChanged(int, int, int, int) and the view will be invalidated.

    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)
    

    Set the scrolled position of your view. This will cause a call to onScrollChanged(int, int, int, int) and the view will be invalidated.

    Parameters
    x   the x position to scroll to
    y   the y position to scroll to
    
    0 讨论(0)
  • 2021-01-01 02:56

    There are two methods to "smooth scroll" rather than jump to a position.

    Check out http://developer.android.com/reference/android/widget/ScrollView.html

    for smoothScrollBy() and smoothScrollTo().

    Hope this helps.

    0 讨论(0)
  • 2021-01-01 03:14
    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);
    
    }
    
    0 讨论(0)
提交回复
热议问题