我是 Android 编程的新手。我有一个带有一些 TextView
和 Button
控件的 UI。如何在这些组件后面设置背景?让我们称之为 background.png
。
原文由 farissyariati 发布,翻译遵循 CC BY-SA 4.0 许可协议
我是 Android 编程的新手。我有一个带有一些 TextView
和 Button
控件的 UI。如何在这些组件后面设置背景?让我们称之为 background.png
。
原文由 farissyariati 发布,翻译遵循 CC BY-SA 4.0 许可协议
First you have to place your background.png
image in your res/drawable/
folder.Later you have to set a parent layout for your TextView
and Button
widgets.I 将考虑 LinearLayout
作为您的父布局,代码如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@drawable/background.png"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button android:text="Button"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
</LinearLayout>
原文由 Vivek Kalkur 发布,翻译遵循 CC BY-SA 3.0 许可协议
4 回答1.1k 阅读✓ 已解决
4 回答1.1k 阅读✓ 已解决
1 回答2.5k 阅读✓ 已解决
3 回答849 阅读✓ 已解决
2 回答2.1k 阅读
2 回答966 阅读✓ 已解决
2 回答697 阅读✓ 已解决
在您的父布局元素中,例如 linearlayout 或其他元素,只需添加
android:background="@drawable/background"
这将设置布局的背景,假设您的图像位于 /drawable 文件夹中。