Android 画廊

//viewpager 各种样式
    compile('com.github.OCNYang:PageTransformerHelp:v1.0.1') {
        exclude group: 'com.android.support', module: 'appcompat-v7'
        exclude group: 'com.android.support', module: 'support-v7'
    }

https://github.com/OCNYang/PageTransformerHelp


 

1.MainXml

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipChildren="false"
        android:orientation="vertical">

        <android.support.v4.view.ViewPager
            android:layout_gravity="center"
            android:id="@+id/mViewPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="60dp"
            android:layout_marginLeft="60dp"
            android:layout_marginRight="60dp"
            android:layout_marginTop="60dp"
            android:clipChildren="false"
            android:overScrollMode="never"/>
    </LinearLayout>
</layout>

2.item.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="@dimen/x10"
    app:cardCornerRadius="@dimen/x20"
    app:cardElevation="@dimen/x10">
    <!--圆角-->
    <!--阴影app:cardElevation="@dimen/x10"-->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tv_card"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="@dimen/font_18" />

        <ImageView
            android:id="@+id/image_card"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            android:src="@mipmap/ic_launcher" />
    </LinearLayout>
</android.support.v7.widget.CardView>

3.PageAdapter

public class ViewPagerAdapter extends PagerAdapter {

    private List<ViewPagerBean> mData;
    private Context mContext;

    public ViewPagerAdapter(List<ViewPagerBean> data, Context context) {
        mData = data;
        mContext = context;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View inflate = LayoutInflater.from(container.getContext()).inflate(R.layout.item_cardviewpager, container, false);
        ImageView imageView1 = (ImageView) inflate.findViewById(R.id.image_card);
        TextView textView = (TextView) inflate.findViewById(R.id.tv_card);

        Glide.with(mContext).load(mData.get(position).getImageUrl()).into(imageView1);
        textView.setText(mData.get(position).getTextTitle()+"");
        container.addView(inflate);
        return inflate;
    }

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

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

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

4.Bean

public class ViewPagerBean {
    private String imageUrl;
    private String textTitle;

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    public String getTextTitle() {
        return textTitle;
    }

    public void setTextTitle(String textTitle) {
        this.textTitle = textTitle;
    }

    public ViewPagerBean(String imageUrl, String textTitle) {
        this.imageUrl = imageUrl;
        this.textTitle = textTitle;
    }
}

5.MainAc

 List<ViewPagerBean> list = new ArrayList<>();
        list.add(new ViewPagerBean("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=415293130,2419074865&fm=27&gp=0.jpg", "我是第一个"));
        list.add(new ViewPagerBean("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1109917053,4211270766&fm=27&gp=0.jpg", "我是第二个"));
        list.add(new ViewPagerBean("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1614455141,2952757874&fm=27&gp=0.jpg", "我是第三个"));
        list.add(new ViewPagerBean("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1768770686,623173162&fm=27&gp=0.jpg", "我是第四个"));
        list.add(new ViewPagerBean("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3258641584,555286175&fm=27&gp=0.jpg", "我是第五个"));
        ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(list, this);
        mViewBinding.mViewPager.setOffscreenPageLimit(list.size());
        mViewBinding.mViewPager.setAdapter(viewPagerAdapter);
        mViewBinding.mViewPager.setPageMargin(40);

//        mViewBinding.mViewPager.setPageTransformer(true,new AlphaAndScalePageTransformer());
        mViewBinding.mViewPager.setPageTransformer(true,new RotateDownPageTransformer());

有一个BUG在 CardView 作为根布局 和 作为子布局 是他么两种情况 ,阴影有明显的差距.

 

RecyclerView

https://github.com/zhangqifan1/Demo_ok5

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值