出处:《Android编程权威指南》第16章-16.7
内容:单击缩放版本照片的DialogFragment,弹出大图
1 创建布局文件dialog_photo.xml
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/crime_photo">
</ImageView>
2 创建PhotoFragment类
public class PhotoFragment extends DialogFragment {
public static final String EXTRA_PHOTO_PATH = "com.bignerdranch.android.criminalintent.photo_path";
private ImageView mImageView;
public static PhotoFragment newInstance(String photoPath) {
Bundle args = new Bundle();
args.putSerializable(EXTRA_PHOTO_PATH, photoPath);
PhotoFragment fragment = new PhotoFragment();
fragment.setArguments(args);
fragment.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
return fragment;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View v = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_photo, null);
mImageView = (ImageView)v.findViewById(R.id.crime_photo);
String path = getArguments().getString(EXTRA_PHOTO_PATH);
Bitmap bitmap = PictureUtils.getScaledBitmap(path, getActivity());
mImageView.setImageBitmap(bitmap);
return new AlertDialog.Builder(getActivity()).setView(v).create();
}
}
3 更新CrimeFragment类
{CSDN:CODE:2236612}