添加一個(gè)新類GlancePictureFragment为障,繼承自 DialogFragment,用來(lái)實(shí)現(xiàn)縮略圖的效果耻蛇,代碼如下:
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;
}
}
為圖片添加點(diǎn)擊事件,代碼如下:
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);
}
});
添加一個(gè)名為dialog_image.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>
效果如下:
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者