当前位置: 代码迷 >> Android >> Android ViewPager 上下滑动-2
  详细解决方案

Android ViewPager 上下滑动-2

热度:71   发布时间:2016-05-01 11:47:21.0
Android ViewPager 左右滑动-2
/***
     * 选中效果
     */
    public void setSelector(int id) {
        for (int i = 0; i < title.length; i++) {
            if (id == i) {
                Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
                        R.drawable.grouplist_item_bg_normal);
                textViews.get(id).setBackgroundDrawable(
                        new BitmapDrawable(bitmap));
                textViews.get(id).setTextColor(Color.RED);
                viewPager.setCurrentItem(i);
            }

            else {
                textViews.get(i).setBackgroundDrawable(new BitmapDrawable());
                textViews.get(i).setTextColor(R.color.black);
            }
        }
    }
   
    void InItView() {
        pageViews = new ArrayList<View>();
        View view01 = getLocalActivityManager().startActivity("search",
                new Intent(this, Search.class)).getDecorView();
        View view02 = getLocalActivityManager().startActivity("manager",
                new Intent(this, Manager.class)).getDecorView();
        View view03 = getLocalActivityManager().startActivity("appinfo",
                new Intent(this, AppInfo.class)).getDecorView();
        pageViews.add(view01);
        pageViews.add(view02);
        pageViews.add(view03);
    }

    public void onClick(View v) {
        setSelector(v.getId());
    }
   
    class myPagerView extends PagerAdapter {
        // 显示数目
        @Override
        public int getCount() {
            return pageViews.size();
        }

        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {
            return arg0 == arg1;
        }

        @Override
        public int getItemPosition(Object object) {
            return super.getItemPosition(object);
        }

        @Override
        public void destroyItem(View arg0, int arg1, Object arg2) {
            ((ViewPager) arg0).removeView(pageViews.get(arg1));
        }

        /***
         * 获取每一个item, 类于listview中的getview
         */
        @Override
        public Object instantiateItem(View arg0, int arg1) {
            ((ViewPager) arg0).addView(pageViews.get(arg1));
            return pageViews.get(arg1);
        }

    }
  相关解决方案