你能帮我配置我的布局吗?我没有达到我想要的效果:
我将ImageView背景设置为红色以解释我想要的是什么:
图片的宽度小于布局的宽度。我想让图片按比例增长并保持其宽高比,直到达到第一张图片的宽高比(我用photoshop手动修改了它),但是当将width =“fill_parent”时,结果是第二张图片,同时将宽度和高度都设置为“fill_parent”时,结果是第三张图片。
我试图结合ScaleType,但没有成功
我该如何实现第一个选项?谢谢
在 XML 中使用 android:adjustViewBounds=true
属性来调整 ImageView
元素的大小。
这个问题通过扩展 ImageView 类在这里得到了解决。
Android ImageView 调整父元素高度和适应宽度
我创建了一个示例,它对我有效。这是 xml 布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:src="@drawable/hydrangeas"
android:layout_height="wrap_content" android:id="@+id/imageView1"
android:scaleType="centerInside"
android:adjustViewBounds="true"
android:background="@android:color/white"
android:layout_width="wrap_content"/>
</LinearLayout>
fitCenter
也适用,查看快照。
<ImageView ... android:scaleType="fitCenter" .. />