【发布时间】:2016-07-31 11:53:16
【问题描述】:
我的应用程序中应该有一个 DialogFragment。这个片段的目的是在我点击其他片段中的缩略图时显示放大的图片。
这是它的布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/zoomed_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
所以基本上,这个 ImageView 应该显示放大的图片,我想在屏幕上尽可能多地显示图片。
我有一个位图,我可以根据它计算出尽可能适合屏幕的显示尺寸。
问题:问题是显示的缩放图片中有多余的空间:
我无法“裁剪”这个额外的空间。我阅读了调整大小的解决方案并执行了以下操作:(在调用 mPhotoView.setImageBitmap(bitmap) 之前,mPhotoView 是我从 findViewById() 获得的 ImageView 实例)
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(getArguments().getString(key_imagePath), options);
float srcWidth = options.outWidth;
float srcHeight = options.outHeight;
FrameLayout.LayoutParams p = new FrameLayout.LayoutParams((int)srcWidth, (int)srcHeight);
view.setLayoutParams(p);
view.requestLayout();
问题:
- 如何从 DialogFragment 的视图中删除这个额外的空白?
- 作为 DialogFragment 是否意味着布局大小将是固定的,或者一般会有类似的视图?
- 会不会是因为 Layout pass 的缘故?
【问题讨论】:
-
您的框架布局 XML 有
match_parent尝试使用wrap_content删除空白。 -
@MarkKeen:我现在正在尝试。谢谢。
-
@MarkKeen :它不适用于 wrap_content
标签: android android-fragments android-dialogfragment