优化照片显示

添加一个新类GlancePictureFragment,继承自 DialogFragment,用来实现缩略图的效果,代码如下:

public class GlancePictureFragment extends DialogFragment {
    private static final String ARG_PATH = "path";
    private ImageView mImage;
    public static GlancePictureFragment newInstance(String path) {
        Bundle args = new Bundle();
        args.putString(ARG_PATH, path);
        GlancePictureFragment fragment = new GlancePictureFragment();
        fragment.setArguments(args);
        return fragment;
    }
    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        String path = getArguments().getString(ARG_PATH);
        final Dialog dialog = new Dialog(getActivity(), R.style.CustomDialogTheme);
        dialog.setContentView(R.layout.dialog_image);
        mImage = (ImageView) dialog.findViewById(R.id.glance_image);
        mImage.setImageBitmap(
                PictureUtils.getScaledBitmap(path, getActivity()));
        mImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        return dialog;
    }
}

为图片添加点击事件,代码如下:

 mPhotoView = (ImageView) v.findViewById(R.id.crime_photo);
        mPhotoView.setOnClickListener(new View.OnClickListener() {
            public String DIALOG_GLANCE_PICTURE;
            @Override
            public void onClick(View view) {
                FragmentManager manager = getFragmentManager();
                GlancePictureFragment dialog = GlancePictureFragment
                        .newInstance(mPhotoFile.getPath());
                dialog.show(manager, DIALOG_GLANCE_PICTURE);
            }
        });

添加一个名为dialog_image.xml的布局文件,代码如下:


    

效果如下:

优化照片显示_第1张图片
1.png
优化照片显示_第2张图片
2.png
优化照片显示_第3张图片
3.png

你可能感兴趣的:(优化照片显示)