背景图像放置 [英] Background Image Placement

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

问题描述

我正在尝试将我的根 LinearLayout 元素(在两个维度中都设置为 fill_parent)设置为具有始终位于屏幕左下角的背景图像,无论设备的方向如何.如果有某种方法可以设置背景图像位置,例如您可以使用background-position: left bottom;"对 css 进行设置,那就太好了.但我没有看到在 Android 中实现这一目标的方法.有没有办法做到这一点?

I'm trying to set my root LinearLayout element (which is set to fill_parent in both dimensions) to have a background image which is always located in the lower left corner of the screen no matter the orientation of the device. It would be excellent if there were some way to set the background image position such as that which you can do with css using "background-position: left bottom;" but I'm not seeing a way to achieve this in Android. Is there a way to do this?

感谢您的帮助.

推荐答案

您必须使用 XML 文件(例如res/drawables/my_drawable.xml")中的位图创建可绘制的自定义位图

You'll have to create a custom bitmap drawable with your bitmap in an XML file (eg "res/drawables/my_drawable.xml"

<?xml version="1.0" encoding="utf-8"?>
<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/my_png_file"
    android:gravity="bottom|left" />

然后将此 drawable xml 设置为视图的背景(@drawables/my_drawable").不过,Android 站点中对可绘制 XML 格式的记录非常少,因此要想自己解决问题绝对不是一件容易的事.

And then set this drawable xml as your view's background ("@drawables/my_drawable"). The drawable XML format is very poorly documented in the Android site, though, so it's definitely not an easy problem to figure out how to solve on your own.

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

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