I am kind of new to Android, and I am stuck with this problem. I have a RecyclerView which holds ImageViews. What I want to do is, when I touch an item, it should enlarge the image to its original size. RecyclerView currently covers one-fifth of the screen. My Adapter is as follows:
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> implements View.OnTouchListener {
private ArrayList<Bitmap> pieces;
private RecyclerViewOnTouchListener touchListener;
public interface RecyclerViewOnTouchListener {
void onTouch(View v, MotionEvent event);
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
ImageView imageViewPiece;
public MyViewHolder(View itemView) {
super(itemView);
this.imageViewPiece = (ImageView) itemView.findViewById(R.id.pieceImage);
}
}
public MyAdapter(ArrayList<Bitmap> pieces, RecyclerViewOnTouchListener touchListener) {
this.pieces = pieces;
this.touchListener = touchListener;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// Inflate layout for recycler view
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recycler_view, parent, false);
MyViewHolder myViewHolder = new MyViewHolder(view);
return myViewHolder;
}
@Override
public void onBindViewHolder(final MyViewHolder holder, final int listPosition) {
ImageView imageView = holder.imageViewPiece;
imageView.setOnTouchListener(this);
imageView.setTag(listPosition);
imageView.setImageBitmap(pieces.get(listPosition));
}
@Override
public int getItemCount() {
return pieces.size();
}
@Override
public boolean onTouch(View v, MotionEvent event) {
ImageView imageView = (ImageView) v.findViewById(R.id.pieceImage);
if (touchListener != null) {
touchListener.onTouch(imageView, event);
}
return false;
}
}
And the related part in my fragment class is as following:
MyAdapter.RecyclerViewOnTouchListener onTouchListener = new MyAdapter.RecyclerViewOnTouchListener() {
@Override
public void onTouch(ImageView v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_DOWN:
// Enlarge image to its original size and remove it from the list, also it should be able to move in the recycler view.
break;
case MotionEvent.ACTION_UP:
// Put image back to its position at list
break;
default:
break;
}
}
};
I suppose its logic should be something like this but I am stuck. I hope I have written enough information about the problem.
My fragment looks like this: http://i.imgur.com/alEG7OP.png
I want to touch a piece on the right and when I do it, it should enlarge to its original size and when I stop touching, it should go back to the list with the same size as the others. I also want to be able to move it.