Resize AlertDialog to fit image exactly

假装没事ソ 提交于 2020-01-06 19:54:16

问题


I have the following AlertDialog with an image inside it:

As you can see there is a small gap just above and just below the image. I'd like to remove that gap.

My layout xml looks like:

<?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>

回答1:


Unless you create the whole dialog by your self, it's really difficult to control those kind of things. However, if you don't mind resizing the image, you could try something like:

<?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>



回答2:


See this question and its answer on how to create a Dialog without any UI, or rather, where anything visible was put there by you.

This question/answer apparently does the same thing, and seems simpler. Haven't tried it, though.




回答3:


The best and easy way to achieve this programmatically is to

setAdjustViewBounds(true);

I am answering this now because I have spent many days on the solution and can't find the answer anywhere.



来源:https://stackoverflow.com/questions/3784236/resize-alertdialog-to-fit-image-exactly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!