安卓:我如何使用图层列表和形状元素时,作为背景设定画一条水平线? [英] Android: How can i use the layer-list and shape elements to draw a horizontal rule when set as background?

查看:262
本文介绍了安卓:我如何使用图层列表和形状元素时,作为背景设定画一条水平线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置的相对或LinearLayout中到自定义绘制的背景。我想要的形状绘制在底部两条水平线,使中心部分透明的(空的)。

下面绘制水平线垂直居中,因为我需要他们对齐到形状的底部。 (如果你添加一个矩形作为一个项目,你可以看到形状扩展到父母的dimenstions,但是线依然集中排列)。

 < XML版本=1.0编码=UTF-8&GT?;
<层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
 <项目>
  <形机器人:形状=行>
      <行程机器人:宽=1dip机器人:颜色=#99b8b9bd/>
      <大小机器人:身高=1dip/>
  < /形状>
 < /项目>
 <项目>
  <形机器人:形状=行的Andr​​oid版本:顶部=1dip>
      <行程机器人:宽=1dip机器人:颜色=#FFFFFFFF/>
      <大小机器人:身高=1dip/>
  < /形状>
 < /项目>
< /层列表>
 

解决方案

找到答案之前,我问完这件事。​​

 < XML版本=1.0编码=UTF-8&GT?;
<层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
    <项目>
      <形状
        机器人:形状=矩形>
            <行程机器人:宽=1DP机器人:颜色=@色/ hr_bottom/>
            [固体机器人:颜色=#00FF0000/>
            <填充安卓底=1DP/>
        < /形状>
   < /项目>

   <项目>
      <形状
        机器人:形状=矩形>
            <行程机器人:宽=1DP机器人:颜色=@色/ hr_top/>
            [固体机器人:颜色=#00FF0000/>
            <填充安卓底=1DP/>
        < /形状>
   < /项目>

    <项目>
      <形状
        机器人:形状=矩形>
            <行程机器人:宽=1DP机器人:颜色=#00000000/>
            [固体机器人:颜色=#00000000/>
        < /形状>
   < /项目>

< /层列表>
 

I want to set the background of a Relative or LinearLayout to a custom drawable. I want the shape to draw two horizontal lines across the bottom, leaving the central part transparent (empty).

The following draws the horizontal lines centered vertically, where as i need them to be aligned to the bottom of the shape. (If you add a rectangle as an item you can see the shape expands to the dimenstions of the parent, but the lines are still centrally aligned).

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
 <item>
  <shape android:shape="line">
      <stroke android:width="1dip" android:color="#99b8b9bd" />
      <size android:height="1dip" />
  </shape>
 </item>
 <item>
  <shape android:shape="line" android:top="1dip">
      <stroke android:width="1dip" android:color="#FFFFFFFF" />
      <size android:height="1dip" />
  </shape>
 </item>
</layer-list>

解决方案

Found the answer before i'd finished asking about it.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
      <shape 
        android:shape="rectangle">
            <stroke android:width="1dp" android:color="@color/hr_bottom" />
            <solid android:color="#00FF0000" />
            <padding android:bottom="1dp"/>
        </shape>
   </item>

   <item>
      <shape 
        android:shape="rectangle">
            <stroke android:width="1dp" android:color="@color/hr_top" />
            <solid android:color="#00FF0000" />
            <padding android:bottom="1dp"/>
        </shape>
   </item>

    <item>
      <shape 
        android:shape="rectangle">
            <stroke android:width="1dp" android:color="#00000000" />
            <solid android:color="#00000000" />
        </shape>
   </item>

</layer-list>

这篇关于安卓:我如何使用图层列表和形状元素时,作为背景设定画一条水平线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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