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

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

问题描述

我试图设置我的根的LinearLayout元件(其被设置为FILL_PARENT在两个方向)具有它总是位于屏幕的左下角不管所述装置的定向的背景图像。如果有一些方法来设置背景图片的位置如,你可以使用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 /可绘制/ 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" />

,然后将该绘制XML作为视图的背景(@可绘制/ my_drawable)。 提拉XML格式记录非常糟糕,在Android的网站,虽然如此,它绝对不是一个简单的问题,找出如何解决你自己的。

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天全站免登陆