开发者

Resize AlertDialog to fit image exactly

开发者 https://www.devze.com 2023-01-17 15:14 出处:网络
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.

I have the following AlertDialog with an image inside it:

Resize AlertDialog to fit image exactly

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/开发者_StackOverflow社区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>


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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消