调整位图内绘制层列表 [英] Resize bitmap inside a drawable layer-list
问题描述
目前我正在开发一个Android应用程序。我想打一个文本(报头)与背景是这样的:
Currently I'm developing a Android application. I want to make a text (a header) with a background that looks like this:
_______
/______/
我有以下的code:
I have the following code:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:startColor="@color/jaarkleur"
android:centerColor="@color/jaarkleur"
android:endColor="#E66C2C00"
android:angle="0" />
<stroke android:width="1dp"
android:color="#ff000000"
/>
</shape>
</item>
<item>
<bitmap android:src="@drawable/overlay_left" android:gravity="left" />
</item>
<item>
<bitmap android:src="@drawable/overlay_right" android:gravity="right" />
</item>
</layer-list>
所以我对图像做这样一个TRANSPARANT三角形,摆放于两端。
So I made to images so with a transparant triangle which are placed at both ends.
这工作正常,头部只有一条线,但是当一个头占据了两行,它看起来是这样的:
This works fine for headers with only one line, but when a header takes up two lines it looks like this:
所以我的问题是:是否有可能调整两个图像,以便看起来是否正确? 谢谢!
So my question is: Is it possible to resize both images so looks correctly? Thank you!
推荐答案
我解决了使用它重新present两(半TRANSPARANT)图像间的角落。
I solved it using two (half-transparant) images which represent the corners.
中的XML看起来是这样的:
The XML looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:startColor="@color/jaarkleur"
android:centerColor="@color/jaarkleur"
android:endColor="#E66C2C00"
android:angle="0" />
<stroke android:width="1dp"
android:color="#ff000000"
/>
</shape>
</item>
<item>
<bitmap android:src="@drawable/overlay_left" android:gravity="left|top" />
</item>
<item>
<bitmap android:src="@drawable/overlay_right" android:gravity="right|bottom" />
</item>
</layer-list>
这篇关于调整位图内绘制层列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!