第二次单击“回收者”视图中的任何图像,我将该图像发送到下一个活动 Images.class ,在这里,我有 CustomAdapterRV扩展了RecyclerView.Adapter , >
@Override
public void onBindViewHolder(@NonNull final CustomAdapterRV.ViewHolder viewHolder, final int position) {
final Model_rv model = modelList.get(position);
viewHolder.imageView.setImageResource(model.getImage());
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
image_position = position;
int childCount = rv.getChildCount();
Intent intent = new Intent(mctx, Images.class);
intent.putExtra("image", model.getImage());
mctx.startActivity(intent);
}
});
}
3rd我在images.class中收到了它
imageView=findViewById(R.id.images);
Intent intent=getIntent();
final int image=intent.getIntExtra("image",0);
imageView.setImageResource(image);
第4个此处,我想在用户左右滑动时获取下一张或上一张图像。我在这里使用 GestureDetector.SimpleOnGestureListener 在这里我使用 onfling 注意onfling可以正常工作
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
float deltaX = e1.getX() - e2.getX();
float deltaY = e1.getY() - e2.getY();
float deltaXAbs = Math.abs(deltaX);
float deltaYAbs = Math.abs(deltaY);
if((deltaXAbs >= MIN_SWIPE_DISTANCE_X) && (deltaXAbs <= MAX_SWIPE_DISTANCE_X))
{
if(deltaX > 0)
{
Toast.makeText(getActivity(), "swipe left", Toast.LENGTH_SHORT).show();
}else
{
Toast.makeText(getActivity(), "swipe rit", Toast.LENGTH_SHORT).show();
}
}
if((deltaYAbs >= MIN_SWIPE_DISTANCE_Y) && (deltaYAbs <= MAX_SWIPE_DISTANCE_Y))
{
if(deltaY > 0)
{
Toast.makeText(getActivity(), "swipe up", Toast.LENGTH_SHORT).show();
}else
{
Toast.makeText(getActivity(), "swipe down", Toast.LENGTH_SHORT).show();
}
}
return true;
}
第5个帮助我如何在滑动时获取下一张图片