我想在我的应用中将图像显示为背景.现在我用这句话:android:background="@drawable/background"in <LineraLayout>.这是.xml代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="overbit.user.MainActivity"
android:background="@drawable/background">
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
现在我得到这个输出:
但我希望这样:
也许有人可以帮助我.谢谢.
The*_*ind 12
有BitmapDrawable,允许这样做.首先,您需要创建一个可绘制资源,如下所示(让它成为项目资源中的文件res/drawable/mybg.xml):
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/background"
android:gravity="center" />
Run Code Online (Sandbox Code Playgroud)
然后将其指定为布局中的后台资源:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="overbit.user.MainActivity"
android:background="@drawable/mybg">
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11339 次 |
| 最近记录: |