定义可绘制形状与JAVA code [英] Defining Drawable Shape with in JAVA code
本文介绍了定义可绘制形状与JAVA code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
喜 我可以定义这个形状,而不使用XML code
Hi Can I define this shape without using xml code
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#34342C" android:endColor="#848486"
android:angle="90" />
<padding android:left="7dp" android:top="5dp" android:right="7dp"
android:bottom="5dp" />
<stroke android:width="1dp" android:color="#FFFFFF" />
</shape>
感谢您的帮助
Thanks for your help
推荐答案
是
- 使用 ShapeDrawable 绘制您的矩形与<一个href="http://developer.android.com/reference/android/graphics/drawable/ShapeDrawable.html#setPadding%28int,%20int,%20int,%20int%29"相对=nofollow> 您需要<填充/ LI>
- 使用涂料与适当的颜色和的描边宽度
- 使用线性渐变并添加这对漆作为<一href="http://developer.android.com/reference/android/graphics/Paint.html#setShader%28android.graphics.Shader%29"相对=nofollow>渲染
- use a ShapeDrawable to draw your rectangle with the padding you require
- using a Paint with the appropriate color and stroke width
- using a Linear gradient and adding this to the Paint as a shader
这篇关于定义可绘制形状与JAVA code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文