I am new to android, i am using RecyclerView to list the images without using third party libraries. It works perfectly but when I click the image, i need to show the image in fragment over the activity.
when onClick
method trigger, call interface method ItemClickListener
@Override
public void ItemClickListener(View view, int position,Bitmap bitmap) {
ActivityFragment frag=new ActivityFragment();
Bundle bundle=new Bundle();
ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
bundle.putParcelable("bitmap", bitmap);
Log.d("fff", String.valueOf(bundle));
frag.setArguments(bundle);
FragmentManager manager=getFragmentManager();
FragmentTransaction transaction=manager.beginTransaction();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.add(R.id.linearLayoutRecyclerView, frag, "bitmappassing");
transaction.addToBackStack("bitmappassing");
transaction.commit();
}
This is ActivityFragment.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View layout= inflater.inflate(R.layout.fragment_activity, container, false);
// Bitmap args=getArguments().getParcelable("bitmap");
Bitmap bitmap=getArguments().getParcelable("bitmap");
Log.d("fff","fragment"+bitmap);
imageView= (ImageView) layout.findViewById(R.id.id_fragmentImageView);
imageView.setImageBitmap(bitmap);
return layout;
}
答案 0 :(得分:2)
您只需使用自定义布局的对话框即可。
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater inflater = ActivityName.this.getLayoutInflater();
View imageDialog = inflater.inflate(R.layout.dialog_image, null);
Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(imageDialog);
dialog.setCanceledOnTouchOutside(true);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
ImageView imgImage = (ImageView) imageDialog.findViewById(R.id.imgImage);
// Set your image
dialog.show();
}
});