如何在Android应用程序中设置垂直动画滚动 [英] How to set vertical animation scrolling in android application

查看:96
本文介绍了如何在Android应用程序中设置垂直动画滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名初学者,无法解决一个问题.我想为ListView设置动画.我想使此列表具有自动使动画垂直缓慢滚动的列表.我阅读了这份文档:链接但是我不知道它是怎么做的.我找不到任何示例.预先感谢.

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 scroll vertical. I read this documentation: link But I have no idea, how it do. And I can't find any example how to do it. Thanks in advance.

推荐答案

这是我制作的一个快速示例.一旦单击 listView 中可见的项目之一,它将开始滚动慢慢地朝最后一个元素移动(考虑到 list.size()-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
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    //        listView.smoothScrollBy(1000,5000);
            listView.smoothScrollToPositionFromTop(list.size()-1,0,5000);
        }
    });

这篇关于如何在Android应用程序中设置垂直动画滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆