ViewPager做出广告轮播特效

上图:


ViewPager做出广告轮播特效_第1张图片
输入图片说明

上代码:


        android:clipChildren="false">
        
            android:layout_marginLeft="38dp"
            android:layout_marginRight="38dp"/>
    

Activity.java

viewpager.setOffscreenPageLimit(3);
viewpager.setAdapter(adapter);
viewpager.setPageTransformer(true, new ViewPager.PageTransformer()
{
    @Override
    public void transformPage(View page, float position)
    {
        //最重要的就是这里了
        float v = Math.abs(position);
        float v1 = (float) (0.2 * (v * v));
        page.setScaleY(1 - v1);
    }
});

PagerAdapter.java

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

import java.util.List;

/**
 * Created by xiaolei on 2017/4/5.
 */

public class HomeBannerAdapter extends PagerAdapter
{
    private List viewLists;
    
    public HomeBannerAdapter(List viewLists)
    {
        this.viewLists = viewLists;
    }
    
    @Override
    public int getCount()
    {                                                                 //获得size  
        return viewLists.size();
    }

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

    @Override
    public void destroyItem(View view, int position, Object object)                       //销毁Item  
    {
        ((ViewPager) view).removeView(viewLists.get(position));
    }

    @Override
    public Object instantiateItem(View view, int position)                                //实例化Item  
    {
        ((ViewPager) view).addView(viewLists.get(position), 0);
        return viewLists.get(position);
    }
}

你可能感兴趣的:(ViewPager做出广告轮播特效)