ViewPage滑动加载大图和点击关注效果《IT蓝豹》

发布时间:2020-06-04 03:47:52 作者:杨光成
来源:网络 阅读:212

ViewPage滑动加载大图和点击关注效果

ViewPage滑动加载大图和点击关注效果,viewpager滑动页面加载多张图片效果,
和点击关注按钮时候的状态变化效果。
本项目来源:https://github.com/SerhatSurguvec/Double-Tap-To-Like
大体实现代码:ViewPagerAdapter里面主要实现。

//ViewPager
public class ViewPagerAdapter extends PagerAdapter {
    // Declare Variables
    Context context;
    LayoutInflater inflater;
    int[] p_w_picpaths;

    public ViewPagerAdapter(Context context, int[] p_w_picpaths) {
        this.context = context;
        this.p_w_picpaths = p_w_picpaths;
    }

    @Override
    public int getCount() {
        return 5;
    }

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

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        ImageView p_w_picpathview;
        final ImageView heartAnim;
        final ImageView likeImg;
        final TextView likeCount;
        TextView whichOfThem;

        inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View itemView = inflater.inflate(R.layout.viewpager_item, container,
                false);


        // Locate the ImageView in viewpager_item.xml
        p_w_picpathview = (ImageView) itemView.findViewById(R.id.p_w_picpath);
        heartAnim = (ImageView) itemView.findViewById(R.id.heart_anim);
        likeImg = (ImageView) itemView.findViewById(R.id.item_comment_like_img);
        likeCount = (TextView) itemView.findViewById(R.id.item_comment_like_count);
        whichOfThem = (TextView) itemView.findViewById(R.id.which);

        whichOfThem.setText((position + 1) + "/" + 5);
        p_w_picpathview.setImageResource(p_w_picpaths[position]);

        final GestureDetector gd = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onDown(MotionEvent e) {
                return true;
            }

            @Override
            public boolean onDoubleTap(MotionEvent e) {

                Animation pulse_fade = AnimationUtils.loadAnimation(context, R.anim.pulse_fade_in);
                pulse_fade.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {
                        heartAnim.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        heartAnim.setVisibility(View.GONE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                heartAnim.startAnimation(pulse_fade);
                likeImg.setImageDrawable(context.getResources().getDrawable(R.drawable.like_active));
                likeCount.setText("3 Likes");
                return true;
            }

            @Override
            public void onLongPress(MotionEvent e) {
                super.onLongPress(e);

            }

            @Override
            public boolean onDoubleTapEvent(MotionEvent e) {
                return true;
            }
        });

        p_w_picpathview.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                return gd.onTouchEvent(event);
            }
        });


        // Add viewpager_item.xml to ViewPager
        (container).addView(itemView);

        return itemView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        // Remove viewpager_item.xml from ViewPager
        ((ViewPager) container).removeView((RelativeLayout) object);

    }
}


 

运行效果:

相关代码


推荐阅读:
  1. RecyclerView加载不同view实现效果--IT蓝豹
  2.   挑战独立开发项目能力--IT蓝豹

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

images 项目 android

上一篇:mongodb 增删改查

下一篇:配置主从DNS服务器

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》