android - 在设置了最大高度和最大宽度的 ImageView 中定位图像

标签 android imageview

我有一个 ImageView,最大高度和最大宽度都设置为 100。下图显然不是正方形,但你可以发挥你的想象力;)

图一:

╔══════════════════════════════════════════════╗
║ ImageView    ╔══════════════╗                ║
║              ║              ║                ║
║              ║ Actual image ║                ║
║              ║              ║                ║
║              ║              ║                ║
║              ║              ║                ║
║              ╚══════════════╝                ║
╚══════════════════════════════════════════════╝

无论如何,如果我尝试将 BitMap 设置为比例不为 1:1 的 ImageView,则图像的位置如图 1 所示。我想要的是将图片放在 ImageView 内的左侧,如下图 2 所示。

图2:

╔══════════════════════════════════════════════╗
║══════════════╗                               ║
║              ║                               ║
║ Actual image ║                               ║
║              ║                               ║
║              ║                               ║
║              ║                               ║
║══════════════╝                               ║
╚══════════════════════════════════════════════╝

您可以在下面的 XML 中看到我的 ImageView。 maxHeightmaxWidthadjustViewBounds 在运行时设置。

<ImageView android:id="@+id/someImage"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textName"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:paddingRight="4dp"
    />

如果有任何区别,这在 RelativeLayout 中。

最佳答案

试试这个

<ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/home_icon" 
     android:scaleType="fitStart"/>

这对我有帮助。

关于android - 在设置了最大高度和最大宽度的 ImageView 中定位图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2762243/

相关文章:

java - 使用 Test Fairy 插件上传 APK 问题

android - 无法使用 Robolectric 4.0.1 运行测试, 'packageDebugUnitTestForUnitTest' 失败

android - 这段代码为什么要用Context呢?

java - 每次单击按钮时如何在 ImageView 中旋转图像?

android - ImageView/ImageButton 中的 srcCompat 和背景有什么不同

android - 如何在 android 中使用拖放框架从一个 LinearLayout 交换到另一个 LinearLayout

java - 如何使用 OrmLite 连接到受密码保护的 SQLite 数据库?

php - C2DM实现PHP代码

ios - 如何在 ViewController 中随机化 3 张图像?

android - 改变我在屏幕上触摸的位图的位置