Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically Fling ListView Android

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 etc. I want to do it with my app on any phone, without monkey.

Thanks, Faisal

like image 246
Faisal Abid Avatar asked Nov 06 '22 20:11

Faisal Abid


2 Answers

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.

like image 53
Matt Briançon Avatar answered Nov 12 '22 16:11

Matt Briançon


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

}
like image 37
ashish Avatar answered Nov 12 '22 18:11

ashish