Android 如何使对话框适合图像?

Android 如何使对话框适合图像?,android,image,dialog,Android,Image,Dialog,我正在使用ActionBarSherlock创建DialogFragment。我正在将图像的id传递给DialogFragment。它只包含ImageView的一部分: <ImageView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/imageF" android:layout_width="wrap_content

我正在使用
ActionBarSherlock
创建
DialogFragment
。我正在将图像的id传递给
DialogFragment
。它只包含ImageView的一部分:

<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/imageF"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical|center_horizontal" />
但每次我得到这个:

对话框不适合图像。我使用
AlertDialog
获得相同的行为(同样如此)

尝试将图像设置为背景(
setBackgroundResource
)时,图像适合对话框(图像填充屏幕截图上显示的未使用空间)

如何避免这种情况并使对话框适合图像?有什么解决办法吗


请提供帮助。

经过长时间的搜索和多次不成功的尝试,我找到了一个解决方案

我需要设置android:adjustViewBounds=“true”

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.dialog, container, false);
        View iv = v.findViewById(R.id.imageF);
        ((ImageView) iv).setImageResource(imgId);
        return v;
    }