如何调整可绘制图层列表中的位图大小?程序化或 XML
How to resize bitmap that have in drawable layer-list? Programmatic or in XML
我正在尝试像这样以正确的方式构建启动画面 https://medium.com/@ssaurel/create-a-splash-screen-on-android-the-right-way-93d6fb444857 为此,我必须将我的应用程序图标 .png 文件作为位图放置在可绘制图层列表中,如下所示
<item
android:drawable="@color/gray"/>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/logo"/>
</item>
现在我该如何调整位图的大小?谢谢...
无法通过 XML 重新调整大小,您可以确认这一点 link。
在代码方法中,有不同的复杂方法。如果想了解更多可以看看这个question
But if your goal is only to change the size, this can be done through ImageView
如果你想将完整的图像设置到使用 match_parent 图像视图的屏幕(最适合启动画面),此方法比其他方法更容易和更快:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:layout_centerInParent="true"
android:src="@drawable/splash_screen" />
</RelativeLayout>
我正在尝试像这样以正确的方式构建启动画面 https://medium.com/@ssaurel/create-a-splash-screen-on-android-the-right-way-93d6fb444857 为此,我必须将我的应用程序图标 .png 文件作为位图放置在可绘制图层列表中,如下所示
<item
android:drawable="@color/gray"/>
<item>
<bitmap
android:gravity="center"
android:src="@drawable/logo"/>
</item>
现在我该如何调整位图的大小?谢谢...
无法通过 XML 重新调整大小,您可以确认这一点 link。
在代码方法中,有不同的复杂方法。如果想了解更多可以看看这个question
But if your goal is only to change the size, this can be done through ImageView
如果你想将完整的图像设置到使用 match_parent 图像视图的屏幕(最适合启动画面),此方法比其他方法更容易和更快:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:layout_centerInParent="true"
android:src="@drawable/splash_screen" />
</RelativeLayout>