android - 如何使对话框适合图像?

标签 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"
    android:layout_height="wrap_content"
    android:gravity="center_vertical|center_horizontal" />

来自 DialogFragment 的代码:

    @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;
    }

但每次我得到这个:

dialog doesn't fit to image

对话框不适合图像。我使用 AlertDialog 得到相同的行为(也是相同的 SO post )。

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

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

请帮忙。

最佳答案

经过长时间的搜索和多次失败的尝试来解决这个问题,我找到了解决方案。

我需要设置 android:adjustViewBounds="true"

关于android - 如何使对话框适合图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12944837/

相关文章:

android - 在 Android Manifest 中隐藏对话框标题栏

java - 如何将条形码 Vision API 与 Google Cardboard 集成?

C# 图像分析库

html - css:在 anchor 标记上添加背景图像 url

php - 如何使用php定义在html页面中单击哪个图像并将图像名称存储在mysql中

iOS 8 - UIAlertController 按钮样式未正确应用

android - Json.put() 函数自动放入双引号

android - 如何在 Android TV 上使用NotificationContentProvider 获取通知计数?

android - 即使安装了 native Microsoft 应用程序,登录始终会打开 Web 对话框 [ms graph 如果可能,请尝试使用共享帐户登录]

c# - 避免在数字上下对话框中按 enter 时发出蜂鸣声