我正在使用 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;
}
但每次我得到这个:
对话框不适合图像。我使用 AlertDialog
得到相同的行为(也是相同的 SO post )。
当尝试将图像设置为背景时 (setBackgroundResource
),图像适合对话框(图像填充未使用的空间,如屏幕截图所示)。
如何避免这种情况并使对话框适合图像?有什么解决方法吗?
请帮忙。
最佳答案
经过长时间的搜索和多次失败的尝试来解决这个问题,我找到了解决方案。
我需要设置 android:adjustViewBounds="true"
。
关于android - 如何使对话框适合图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12944837/