调整AlertDialog恰好适合图像(Resize AlertDialog to fit imag

2019-11-04 07:22发布

我已经在里面坐了图像以下AlertDialog:

正如你可以看到有一个小的差距正上方和正下面的图片。 我想删除这个空白。

我的布局XML是什么样子:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/alert_thumb_root"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" >

  <ImageView android:id="@+id/thumb"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content" />
</LinearLayout>

Answer 1:

除非你通过你的自我创建整个对话,这真的很难控制这种事情。 但是,如果你不介意调整图像大小,你可以尝试这样的:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/alert_thumb_root"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" >

  <ImageView android:id="@+id/thumb"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:scaleType="fitXY"/>
</LinearLayout>


Answer 2:

见这个问题和它如何没有任何UI创建一个对话框答案,或者说,在任何可见被你放在那里。

这个问题/答案显然是做同样的事情,而且似乎更简单。 还没有尝试过,但。



Answer 3:

以编程方式实现这一目标的最好的和简单的方法是

setAdjustViewBounds(true);

我现在回答这个问题,因为我花了许多天的解决方案并不能在任何地方找到答案。



文章来源: Resize AlertDialog to fit image exactly