如何在XML中的可绘制对象上获取重力``底部'' [英] How to get gravity 'bottom' working on a drawable in xml

查看:64
本文介绍了如何在XML中的可绘制对象上获取重力``底部''的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的目标.我想在我的FrameLayout上使用浅灰色背景,并在其底下使用黑色分隔线(仅在底下,而不是周围).到目前为止,我有这个:

I have a simple aim. I want a light grey background on my FrameLayout with a black dividing line underneath it (only undernearth, not all around). So far I have this:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle" android:gravity="center">
            <solid android:color="#EEEEEE" />
        </shape>
    </item>
    <item>
        <shape android:shape="line" android:gravity="bottom" >
            <stroke android:width="1dip" android:color="#010101"/>
        </shape>
    </item>
</layer-list>

但是它画一条穿过中心的线,即忽略了gravity ="bottom"位.我该如何解决?

But it draws the line through the centre, i.e. ignores the gravity='bottom' bit. How can I fix this?

这个问题非常很久了.所选答案可能与当前API一致,也可能不符合当前API等.建议您开始自己的问题,而不要添加到不再受监视的问题中.

This question is very old. The selected answer may or may not be in-line with current APIs, etc. You are encouraged to start your own question rather than add to this one, which is no longer monitored.

推荐答案

为此,我建议使用九补丁图像-这是一个应做的示例:

I'd recommend using a nine-patch image for this - here's an example that should do the job:

(它很小,但在那里!)

如果将其放置在可绘制的文件夹中,并为其设置FrameLayout的背景,则应该获得所需的结果.内容将进入灰色区域,并且#010101像素将水平拉伸以在底部形成一条线.只需确保保留.9.png扩展名,以确保将其作为九个补丁加载即可.

(It's only tiny but it is there!)

If you place this in your drawable folder and set your FrameLayout's background to it then you should get the desired result. The content will go in the grey area and the #010101 pixel will be stretched horizontally to form a line at the bottom. Just make sure to keep the .9.png extension to ensure it gets loaded as a nine-patch.

希望对您有帮助

这篇关于如何在XML中的可绘制对象上获取重力``底部''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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