【问题标题】:Resize AlertDialog to fit image exactly调整 AlertDialog 的大小以完全适合图像
【发布时间】:2010-09-24 04:41:44
【问题描述】:

我有以下 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>

【问题讨论】:

  • 它可以工作,但就像你说的那样,它确实会调整图像的大小。我不明白为什么 Android 只是不让它和图片一样大......让它变大的原因是什么?

标签: android xml imageview android-alertdialog


【解决方案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>

【讨论】:

    【解决方案2】:

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

    setAdjustViewBounds(true);

    我现在正在回答这个问题,因为我在解决方案上花了很多天,但在任何地方都找不到答案。

    【讨论】:

      猜你喜欢
      • 2015-03-26
      • 2011-09-30
      • 2011-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多