【问题标题】:Resizing of DialogFragment at runtime在运行时调整 DialogFragment 的大小
【发布时间】: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();

问题:

  1. 如何从 DialogFragment 的视图中删除这个额外的空白?
  2. 作为 DialogFragment 是否意味着布局大小将是固定的,或者一般会有类似的视图?
  3. 会不会是因为 Layout pass 的缘故?

【问题讨论】:

  • 您的框架布局 XML 有 match_parent 尝试使用 wrap_content 删除空白。
  • @MarkKeen:我现在正在尝试。谢谢。
  • @MarkKeen :它不适用于 wrap_content

标签: android android-fragments android-dialogfragment


【解决方案1】:

将第一个 FrameLayout's heightwidth 更改为“wrap_content”不起作用? (同时将您的imageView 设置为您喜欢的固定大小。)

android:layout_width="wrap_content
android:layout_height="wrap_content">

【讨论】:

  • 那你为什么不为你的对话框使用自定义布局。我经常使用它们。
  • 自定义布局...?我没明白。你能详细说明一下吗?
  • 是的,我们可以使用我们自己的自定义布局和我们自己的对话框样式。有几个例子。
猜你喜欢
  • 1970-01-01
  • 2011-03-29
  • 2014-09-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-30
  • 2014-05-01
  • 2016-10-11
相关资源
最近更新 更多