相关疑难解决方法(0)

将图像缩放到最大可用宽度,保持纵横比并避免ImageView额外空间

我有这个简单的布局XML和一个30X30像素的green_square.png文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:background="@color/red"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:adjustViewBounds="true"
        android:scaleType="fitStart"
        android:src="@drawable/green_square"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我想要实现的是缩放图像以填充父宽度,保持它的纵横比,而没有ImageView的额外空间.

我在ImageView中添加了一个红色背景,仅供参考我想要避免的额外空间.

这是我的目标

layout android scale fill-parent

17
推荐指数
2
解决办法
2万
查看次数

标签 统计

android ×1

fill-parent ×1

layout ×1

scale ×1