在ViewPager为2秒后pageadapter自动滚动图片 [英] Auto scroll images after 2 seconds in ViewPager by pageadapter

查看:162
本文介绍了在ViewPager为2秒后pageadapter自动滚动图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建imagescroll视图。有在两个图像的活动。第一个用户可以滚动到这是工作的精细图像。经过2秒和第二自动滚动图像。我尝试了许多例子,但我无法做到这一点。所以我在这里发帖。

I am create a imagescroll view. There is two activity in images. first user can scroll to image which is working fine. and second auto-scroll images after 2 second. i tried a number of example but i am unable to do it . so i am posting here .

请Android专家,检​​查一下。

please android expert check it.

我使用它滚动图像。

MyPagerAdapter adapter = new MyPagerAdapter();
        final ViewPager myPager = (ViewPager) findViewById(R.id.pager);
        myPager.setAdapter(adapter);
        adapter.notifyDataSetChanged();


private class MyPagerAdapter extends PagerAdapter {

        public int getCount() {
            return homescreenList.size();
        }

        public Object instantiateItem(View collection, int position) {
         try {
            LinearLayout images = new LinearLayout(collection.getContext());

               ImageView image = new ImageView(collection.getContext());
               image.setPadding(20, 0, 20, 0);  

            images.addView(image);

            ((ViewPager) collection).addView(images, 0); }
            return images;
         } catch(Exception e) {
                System.out.println("error:"+e.toString());
            }

            return position;
        }

感谢您

推荐答案

您要滚动的 ViewPager 2秒延迟,对吧?

You want to scroll the ViewPager delayed by 2 seconds, right?

您需要为两件事情:

  • Wait for two seconds, by calling your code delayed with View.postDelayed(..., 2000L)
  • Scroll to the right position by View.scrollBy() or scrollTo()

注:我认为链接不指向的确切位置。您必须在网页中搜索像 scrollBy scrollTo方法 postDelayed

Remark: I think the links do not point to the exact position. You must search on the web page for the method like scrollBy, scrollTo or postDelayed.

这篇关于在ViewPager为2秒后pageadapter自动滚动图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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