美文网首页
优化照片显示

优化照片显示

作者: 圈圈_勿忘初心 | 来源:发表于2017-05-01 17:47 被阅读0次
    1. 新建一个 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_glance);
    
            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;
        }
    }
    
    1. 在图片的点击事件中声明
            mPhotoView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    FragmentManager manager = getFragmentManager();
                    GlancePictureFragment dialog = GlancePictureFragment
                            .newInstance(mPhotoFile.getPath());
                    dialog.show(manager, DIALOG_GLANCE_PICTURE);
                }
            });
    
    1. 添加dialog_image_glance.xml布局文件
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:id="@+id/glance_image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </LinearLayout>
    
    1. 在style.xml中添加自定义的主题
    略缩图 点击略缩图后查看陋习现场细节

    相关文章

      网友评论

          本文标题:优化照片显示

          本文链接:https://www.haomeiwen.com/subject/xwtqtxtx.html