问题描述
我想创建与背景像这样的底栏:
I am trying to create a bottom bar with the background like this :
我目前使用下面的code:
I am currently using the following code :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient android:endColor="#000000" android:startColor="#696969"
android:centerColor="#696969" android:angle="270" />
<stroke android:color="#696969" />
<padding android:left="2dp" android:top="3dp" android:right="2dp"
android:bottom="3dp" />
</shape>
</item>
</selector>
但输出看起来像这样...
But the output looks like this ... :
如何获取两色的背景是什么?请建议..谢谢
How to get this ,two colored background ?Please suggest..Thanks
推荐答案
正如其他人所指出的,一个ninepatch将是理想在这种情况下的(并不会花费太多的内存)的。使用XML解决办法是不是最佳的。下面是一些你可以试试:
As others pointed out, a ninepatch would be ideal in this situation (and won't take much memory). Working around with XML is not optimal. Here is something you can try:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:bottom="20dp">
<shape android:shape="rectangle" >
<size android:height="20dp" />
<solid android:color="#ff0000" />
</shape>
</item>
<item android:top="20dp">
<shape android:shape="rectangle" >
<size android:height="20dp" />
<solid android:color="#0000ff" />
</shape>
</item>
</layer-list>
在这种情况下,你的观点被认为是beeing 40dp高的
这是一个图层列表,在不同颜色的两个街区。使用XML方法的问题是,不能块的高度调整到一个百分比(= 50%)。你必须使用一半的实际视图大小的DP。这意味着你必须每次调整此绘制你改变你观点的高度/布局。一个ninepatch会适应这种自动。
It's a layer list with two blocks in different colors. The problem with the XML approach is that you can't adjust the height of the blocks to a percentage (=50%). You have to use half of the actual view size in dp. Which means you have to adjust this drawable each time you change your view height/layout. A ninepatch would adjust to this automatically.
这篇关于带状背景,两种颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!