【发布时间】:2020-07-26 07:44:00
【问题描述】:
我的 ImageView 可以通过 scaleType = "fitCenter" 将我的 file.png 保持为矩形并在不同的屏幕/旋转上变小/变大,从而极大地缩放我的 file.png。 此 ImageView 在具有相同背景文件的 LinearLayout 内。 问题是,在背景缩放后我无法获得相同的结果 - 源图片总是被水平拉伸或变大。
这是我的代码:
<LinearLayout
android:id="@+id/layout_button_quiz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/scaling_background">
<ImageView
android:id="@+id/button_quiz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/brain_off"
android:scaleType="fitCenter"/>
</LinearLayout>
这是我尝试过的背景缩放解决方案,但不起作用:
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/brain_off"
android:scaleType="fitCenter"/>
总结一下: 我希望 LinearLayout 的背景与其中的 ImageView 缩放相同,即 scaleType=fitCenter。
【问题讨论】:
标签: android kotlin background imageview scaling