Skip to content Skip to sidebar Skip to footer

How To Set Vertical Animation Scrolling In Android Application

I'm a beginner developer and I can't solve one problem. I want to set an animation for a ListView. I would like to make that this list has animation making automaticly a slow scrol

Solution 1:

Here is a quick sample that I've made.Once you click on one of the items visible in listView it will start scrolling slowly towards the last element(given the list.size()-1).

Make sure you have enough items added to the list view.

You can adjust those arguments, also you can choose between those two options.

 listView = findViewById(R.id.listView);
    listView.setSmoothScrollbarEnabled(true);

    final ArrayList<String> list =  new ArrayList<>();
    list.add("1 element");
    list.add("2 elements");
    list.add("3 elements");
    list.add("4 elements");
    list.add("5 elements");
    list.add("6 elements");
    list.add("7 elements");
    list.add("8 elements");
    list.add("9 elements");
    list.add("1 element");
    list.add("2 elements");
    list.add("3 elements");
    list.add("4 elements");
    list.add("5 elements");
    list.add("6 elements");
    list.add("7 elements");
    list.add("8 elements");

    ArrayAdapter arrayAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,list);
    listView.setAdapter(arrayAdapter);


    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        publicvoidonItemClick(AdapterView<?> parent, View view, int position, long id) {
    //        listView.smoothScrollBy(1000,5000);
            listView.smoothScrollToPositionFromTop(list.size()-1,0,5000);
        }
    });

Post a Comment for "How To Set Vertical Animation Scrolling In Android Application"