2016-07-31 61 views
0

我应该在我的应用程序中有一个DialogFragment。这个片段的目的是显示放大的图片,如果我点击其他片段中的缩略图。在运行时调整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的应该显示在PIC的放大,我想显示PIC尽可能地在屏幕上。

我有一个位图,我可以根据屏幕的尺寸计算出适合屏幕的显示尺寸。

问题:的问题是在显示的缩放PIC的额外空间:

肖像: enter image description here

景观: enter image description here

我不能“作物“这个额外的空间。我读了解决调整大小和我做了以下内容:(调用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. 是否有可能是因为布局传递?
+0

你的框架布局XML具有'match_parent'与'wrap_content'尝试删除空白。 –

+0

@MarkKeen:我正在尝试。谢谢。 –

+0

@MarkKeen:它不适用于wrap_content –

回答

0

向第一个FrameLayout'sheightwidth补充“wrap_content”不起作用? (在设置你的imageView在一个固定大小的,只要你喜欢。)

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

它不适用于wrap_content。 –

+0

那么为什么你不使用自定义布局为您的对话框。我用它们很多。 –

+0

自定义布局...?我没有得到。你能否详细说明一下? –

相关问题