让viewPager上下滑

用到的castorflex库
首先添加依赖:
compile 'com.github.castorflex.verticalviewpager:library:19.0.1'
xml文件中使用
    android:id="@+id/viewpage_show_img"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


拿到控件的对象
声明adapter
 
  
package com.legent.ui.ext.adapters;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;

import java.util.List;

/**
 * Created by sylar on 15/6/4.
 */
public class MyPageAdapter extends PagerAdapter {

    protected List list = Lists.newArrayList();

    public void loadViews(List views) {

        list.clear();
        notifyDataSetChanged();

        if (views != null && views.size() > 0) {
            list.addAll(views);
            notifyDataSetChanged();
        }
    }

    public List getViews() {
        return list;
    }

    public View getPage(int position) {
        Preconditions.checkState(position >= 0 && position < list.size(), "参数越界:ExtPageAdapter.getPage()");
        return list.get(position);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(list.get(position));
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = list.get(position);
        container.addView(view);
        return view;
    }
}
viewPager.setAdapter(adapter);
不用设置什么横向的竖向的。往里面传view就可以使用。也可以用于页面fragment。我在此仅用于Ui部分页面。给出

github地址:https://github.com/castorflex/VerticalViewPager

你可能感兴趣的:(API的使用,as的开源框架的配置)