如何在背景显示中设置图像? [英] How to set image in background display?

查看:71
本文介绍了如何在背景显示中设置图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在App的背景中设置图像吗? 如何设置?

I want to set a image in background of App? How to set this?

推荐答案

将背景PNG放置在可绘制"资源文件夹中(假设在代码段中为mybackground.png).

Put your background PNG in the 'drawable' resources folder (we assume it's mybackground.png in our snippets).

如果您使用XML布局,则将以下内容添加到顶级容器元素中:

If you use the XML layouts add the following to your top level container element:

android:background="@drawable/mybackground"

例如:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

或者,如果您动态地构建视图,请在Activity onCreate方法中执行以下操作:

Or if you construct your view dynamically, then do the following in the Activity onCreate method:

view.setBackgroundDrawable(R.drawable.mybackground)

这篇关于如何在背景显示中设置图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆