3

I have a recycler view which displays list of products and there is a cart icon in each recycler view row item. On clicking cart Icon i want the product image to duplicate rescale and move to top right corner into cart icon on the action bar.

My Approach:

Created a ImageView in row item xml of recyclerview and made it invisible initially. on clicking cart icon from recyclerview made that image view visible and populated image view with image url and added translate animation from start and end position.

Current Result:

the image move within respective single item row and disappears once it hits the boundary of row item.. I mean the image is not coming out of row item not reaching top action bar menu item.

Solution Tried:

public static void setAllParentsClip(View v, boolean enabled) {
        while (v.getParent() != null && v.getParent() instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) v.getParent();
            viewGroup.setClipChildren(enabled);
            viewGroup.setClipToPadding(enabled);
            v = viewGroup;
        }
    }

Also manually set all parents in xml:

android:clipChildren="false"
android:clipToPadding="false"

Still the image is disappearing after it touches boundary of row item.. Any suggestions will be a great help

Code for My RecyclerView Adapter:

public class TrendingItemsAdapter extends RecyclerView.Adapter<TrendingItemsAdapter.MyViewHolder> {

    private List<ProductEventDetail> productEventDetailList;
    private Context context;


    public TrendingItemsAdapter (List<ProductEventDetail> productEventDetailList){
        this.productEventDetailList=productEventDetailList;
    }


    public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private TextView productName;
        private TextView progressDisplay;
        private ImageView imageView, addToCart,animImg;
        private ProgressBar progressBar;

        @TargetApi(Build.VERSION_CODES.LOLLIPOP)
        public MyViewHolder(View view) {
            super(view);
            productName=(TextView)view.findViewById(R.id.trending_Product_Name);
            imageView=(ImageView)view.findViewById(R.id.trending_product_img);
            addToCart=(ImageView)view.findViewById(R.id.add_to_cart);
            animImg=(ImageView)view.findViewById(R.id.animProductImg);
            progressDisplay=(TextView)view.findViewById(R.id.event_progress_value);
            progressBar=(ProgressBar)view.findViewById(R.id.event_progress);
            progressBar.setProgressDrawable(context.getDrawable(R.drawable.progress_tint));

            addToCart.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if(v.getId()==addToCart.getId()){

                Toast.makeText(context,productEventDetailList.get(getAdapterPosition()).getProductName(),Toast.LENGTH_SHORT).show();
                setAllParentsClip(animImg,false);

                // Animation code

                Animations anim = new Animations();
                int fromLoc[] = new int[2];
                imageView.getLocationOnScreen(fromLoc);
                animImg.setVisibility(View.VISIBLE);

                Glide.with(context)
                        .load(productEventDetailList.get(getAdapterPosition()).getProductImageUrl())
                        .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                        .fitCenter()
                        .into(animImg);

                float startX = fromLoc[0];
                float startY = fromLoc[1];
                Animation a = anim.fromAtoB(startX,startY, 1028, 143, animL,2000);
                animImg.setAnimation(a);
                a.startNow();

            }



        }

        Animation.AnimationListener animL = new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                //this is just a method call you can create to delete the animated view or hide it until you need it again.
                animImg.setVisibility(View.GONE);
            }
        };
    }



    @Override
    public TrendingItemsAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        context=parent.getContext();

        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.trending_item_row_detail, parent, false);

        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callProductEventDetails();
            }
        });


        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(TrendingItemsAdapter.MyViewHolder holder, int position) {

        ProductEventDetail productEventDetail= productEventDetailList.get(position);
        holder.productName.setText(productEventDetail.getProductName()+ " xxxx xxxxxxxxxxxxxxxx..");
        holder.progressBar.setProgress(productEventDetail.getEventProgressStatus());
        holder.progressDisplay.setText(String.valueOf(productEventDetail.getEventProgressStatus())+"% ");

        Glide.with(context)
                .load(productEventDetail.getProductImageUrl())
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .fitCenter()
                .into(holder.imageView);


    }

    @Override
    public int getItemCount() {
        return productEventDetailList.size();
    }

private void callProductEventDetails(){
    Intent intent= new Intent(context, ProductEventDetailActivity.class);
    intent.putExtra("eventStatus","inProgress");
    context.startActivity(intent);
}

    public static void setAllParentsClip(View v, boolean enabled) {
        while (v.getParent() != null && v.getParent() instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) v.getParent();
            viewGroup.setClipChildren(enabled);
            viewGroup.setClipToPadding(enabled);
            v = viewGroup;
        }
    }
    }
Moulesh
  • 2,762
  • 1
  • 22
  • 32
  • @FlorescuGeorgeCătălin yeah... I kinda partially did it i'm able to send the image to cart with its size as static... but resizing it as it moves up leads it away from target... but if its a image with static size it moves exactly into cart... – Moulesh Dec 21 '16 at 11:09
  • No man this code wont work... since I partially achieved it i could not post it as a solution... U need any help ?? – Moulesh Dec 21 '16 at 11:13
  • Yeah, if you want.. I wanna se your code where you create animation and start it, please. Maybe we can figure out how to do it.. – Cătălin Florescu Dec 21 '16 at 11:15
  • http://stackoverflow.com/questions/28002961/how-to-implement-custom-listview-text-animation check this out.. it has soln for textview and i replicated the same for image view... but im not able to scale image gradually... lemme know if you are able to fix scaling issue.. – Moulesh Dec 21 '16 at 11:20

1 Answers1

0

I think you are looking for add to cart animation , you can find solution here fly to cart animation

Community
  • 1
  • 1
satvinder singh
  • 1,152
  • 1
  • 12
  • 22