如何添加边框线的布局,除了在底部? [英] How to add border around linear layout except at the bottom?

查看:167
本文介绍了如何添加边框线的布局,除了在底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何添加边框线的布局,除了在底部? 的LinearLayout需要有边界的左侧,顶部和右侧,但不是在底部。

解决方案

在绘制文件夹中创建名为border.xml XML文件,并把下面的code在里面。

 < XML版本=1.0编码=UTF-8&GT?;
 <层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
  <项目>
    <形机器人:形状=矩形>
      [固体机器人:颜色=#FF0000/>
    < /形状>
  < /项目>
    <项目的android:左=5DP机器人:右=5DP机器人:顶部=5DP>
     <形机器人:形状=矩形>
      [固体机器人:颜色=#000000/>
    < /形状>
   < /项目>
 < /层列表>
 

然后背景添加到您喜欢这个线性布局:

 安卓背景=@可绘制/边框
 

编辑:

这是XML用的Galaxy S运行的姜饼2.3.3测试并完美运行,如下面的图片:

同时

与Galaxy S的3运行的豆形软糖4.1.2 ,然后跑了完美的,如下面的图像测试

最后它可以完美地与所有API

编辑2:

有也可以用一个冲程以保持背景为透明,同时仍保持一个边界,除了在与下列code中的底部进行。

 < XML版本=1.0编码=UTF-8&GT?;
 <层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
   <项目的android:左=0dp机器人:右=0dp机器人:顶部=0dp
        机器人:底部= -  10dp>
    <形机器人:形状=矩形>
     <行程机器人:宽=10dp机器人:颜色=#B22222/>
    < /形状>
   < /项目>
 < /层列表>
 

希望这种帮助。

How to add border around linear layout except at the bottom ? LinearLayout needs to have border at left, top and right side but not at the bottom.

解决方案

Create an XML file named border.xml in the drawable folder and put the following code in it.

 <?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="#FF0000" /> 
    </shape>
  </item>   
    <item android:left="5dp" android:right="5dp"  android:top="5dp" >  
     <shape android:shape="rectangle"> 
      <solid android:color="#000000" />
    </shape>
   </item>    
 </layer-list> 

Then add a background to your linear layout like this:

         android:background="@drawable/border"

EDIT :

This XML was tested with a galaxy s running GingerBread 2.3.3 and ran perfectly as shown in image below:

ALSO

tested with galaxy s 3 running JellyBean 4.1.2 and ran perfectly as shown in image below :

Finally its works perfectly with all APIs

EDIT 2 :

It can also be done using a stroke to keep the background as transparent while still keeping a border except at the bottom with the following code.

<?xml version="1.0" encoding="utf-8"?>
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:left="0dp" android:right="0dp"  android:top="0dp"  
        android:bottom="-10dp"> 
    <shape android:shape="rectangle">
     <stroke android:width="10dp" android:color="#B22222" />
    </shape>
   </item>  
 </layer-list> 

hope this help .

这篇关于如何添加边框线的布局,除了在底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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