如何在线性布局周围添加边框(底部除外)?
LinearLayout 需要在左侧、顶部和右侧有边框,但底部不需要。
在drawable文件夹中创建一个名为border.xml的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="#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>
然后向线性布局添加背景,如下所示:
android:background="@drawable/border"
EDIT :
此 XML 经过 Galaxy 运行测试姜饼2.3.3并完美运行,如下图所示:
ALSO
在 Galaxy s 3 上运行进行测试果冻豆 4.1.2并完美运行,如下图所示:
最后它可以与所有 API 完美配合
EDIT 2 :
也可以使用描边来保持背景透明,同时仍然保留边框(底部除外),使用以下代码。
<?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>
希望这有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)