美文网首页
安卓画廊效果

安卓画廊效果

作者: 默默_大魔王 | 来源:发表于2022-04-19 17:45 被阅读0次

1:效果图

645cffcaf8c68ad7fc2eef256e37a4c.jpg 04a4c299711908a1e90a360e7786b24.jpg a6dcdda58333bc3ef3666a595fff265.jpg

2:代码

//首先创建一个ZoomOutPageTransformer
public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
//缩小倍数可以调节
    private static final float MAX_SCALE = 1f;
    private static final float MIN_SCALE = 0.6f;//0.85f

    @Override
    public void transformPage(@NonNull View page, float position) {


        if (position <= 1) {

            float scaleFactor = MIN_SCALE + (1 - Math.abs(position)) * (MAX_SCALE - MIN_SCALE);

            page.setScaleX(scaleFactor);

            if (position > 0) {

                page.setTranslationX(-scaleFactor * 2);

            } else if (position < 0) {

                page.setTranslationX(scaleFactor * 2);

            }

            page.setScaleY(scaleFactor);

        } else {

            page.setScaleX(MIN_SCALE);

            page.setScaleY(MIN_SCALE);
        }

    }
}

2:创建activity代码


        List<String> urlList = new ArrayList<>();
        urlList.add("https://tenfei03.cfp.cn/creative/vcg/800/new/VCG41N697946430.jpg");
        urlList.add("https://tenfei04.cfp.cn/creative/vcg/800/new/VCG41N970090320.jpg");
        urlList.add("https://tenfei02.cfp.cn/creative/vcg/800/version23/VCG41615107150.jpg");
        mViewPager.setAdapter(new FlowerAdapter(this, urlList));
        mViewPager.setPageMargin(20);
        mViewPager.setOffscreenPageLimit(urlList.size());
        mViewPager.setPageTransformer(true, new ZoomOutPageTransformer());//设置画廊模式



3:xml代码

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/color_f2f2f2"
    android:clipChildren="false">



    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="@dimen/dp200"
        android:layout_height="@dimen/dp200"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:layout_marginBottom="30dp"
        android:clipChildren="false"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/img_flower"/>



</android.support.constraint.ConstraintLayout>

4:适配器

public class FlowerAdapter extends PagerAdapter {

    private List<String> mData;

    private Context mContext;

    @Override
    public int getCount() {
        return mData.size();// 返回数据的个数
    }

    public FlowerAdapter(Context ctx, List<String> data) {
        this.mContext = ctx;
        this.mData = data;
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;// 过滤和缓存的作用

    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View view = View.inflate(container.getContext(), R.layout.result_flower_item, null);

        ImageView imageView = view.findViewById(R.id.iv_photo);
        Glide.with(mContext).load(mData.get(position)).into(imageView);

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(mContext, "当前条目:" + position, Toast.LENGTH_SHORT).show();
            }

        });
        container.addView(view);//添加到父控件

        return view;
    }
}

你要还不会,就加我微信,我去你家教你

相关文章

  • 安卓画廊效果

    1:效果图 2:代码 2:创建activity代码 3:xml代码 4:适配器 你要还不会,就加我微信,我去你家教你

  • 安卓自定义View-画圆

    效果图 代码 安卓开发入门教程系列汇总 安卓发展历程及前景 安卓发展历程 安卓开发前景展望 初探安卓 安装开发工...

  • 安卓动画样例-圆环变多变少

    效果图 代码 安卓开发入门教程系列汇总 安卓发展历程及前景 安卓发展历程 安卓开发前景展望 初探安卓 安装开发工...

  • 安卓动画样例-放大缩小

    效果图 实现代码 安卓开发入门教程系列汇总 安卓发展历程及前景 安卓发展历程 安卓开发前景展望 初探安卓 安装开...

  • 安卓和ios实现ActionSheet

    安卓和ios实现ActionSheet 这是安卓的效果,ios的效果同上。 在项目里用到react-native-...

  • IOS微信webview中 @keyframes中 backgr

    原写法: 期待效果:可以精准还原设计稿适配安卓与IOS系统。 实际效果 安卓系统可以正常显示 IOS系统 back...

  • 安卓用shape画背景边框

    效果图: 代码: shape_rec_blue.xml 使用 附录: 安卓用shape画圆 安卓开发技术分享: h...

  • (技术)说说Android 开屏广告页的适配

    安卓机型多不多?多....安卓开屏广告的适配麻烦不麻烦?麻烦安卓开屏广告的适配能不能实现?能先上个效果图: 想不想...

  • 画廊效果

    这两天研究画廊效果,在github 上发现一个还不错的开源项目,集成了一下,下面来看下效果 下面看下集成过程首先在...

  • Flutter TabBar吸顶效果

    Flutter TabBar吸顶效果,先上图 做过安卓的知道,安卓里CoordinatorLayout+ AppB...

网友评论

      本文标题:安卓画廊效果

      本文链接:https://www.haomeiwen.com/subject/scteertx.html