形状可绘制为背景,一个线在底部 [英] Shape drawable as background, a line at the bottom

查看:177
本文介绍了形状可绘制为背景,一个线在底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是绘制作为一个TextView的背景只是有文字下方的分隔线。一个与此绘制-XML achivied它:

I am using a drawable as a background of a TextView just to have a divider line below the text. A achivied it with this drawable-xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape 
        android:shape="rectangle">
            <solid android:color="#FFDDDDDD" />
            <gradient 
                android:angle="0"
                android:startColor="#FFAAAAAA"
                android:endColor="#FFEEEEEE"
                />
        </shape>
    </item>

    <item android:bottom="2dp">
        <shape 
        android:shape="rectangle">
            <solid android:color="#FF000000" />
        </shape>
    </item>

</layer-list>

但这种方法绘制一个黑色的矩形上方的彩色矩形。我想刚才的线形状,没有黑色矩形底部,因为黑色是不是透明的。我怎么能做到这一点?

But this method draws a colored rectangle above a black rectangle. I would like to have just the line at the bottom of the shape with no black rectangle because black is not transparent. How could I achieve that?

推荐答案

在一般情况下,我尝试一塌糊涂尽可能少与背景,除非绝对必要的,因为这样做会覆盖默认的背景色为国家为重点,pressed,等我建议只使用一个额外的视图(在垂直的LinearLayout),你需要它是厚。例如:

In general, I try to mess as little as possible with backgrounds unless absolutely necessary, since doing so overrides the default background colors that have states for focused, pressed, etc. I suggest just using an additional view (in a vertical LinearLayout) that is as thick as you need it to be. For example:

 <View 
       android:background="#FF000000" 
       android:layout_height="2dp" 
       android:layout_width="fill_parent"/>

这篇关于形状可绘制为背景,一个线在底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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