使用图片给Linerlayout等做背景的时候图片会被不同程度拉伸
<LinearLayout
android:layout_width="match_parent"
android:background="@drawable/bg"
android:layout_height="match_parent"/>
我们可以在xml设置android:background属性时,使用标签
drawable/bg.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="bottom"
android:dither="true"
android:src="@mipmap/login_background"
android:tileMode="disabled"/>
android:gravity可以自行调整以适应显示效果
这样图片就不会被拉伸了

本文介绍了一种在Android中使用图片作为LinearLayout背景时防止图片被拉伸的方法。通过使用特定的XML配置文件,可以确保背景图片按照预期的方式显示,同时保持其原始比例。

被折叠的 条评论
为什么被折叠?



