2012-07-16 62 views
2

我想强调一个TextView用弯曲线,就像这样:创建一个弯曲的线条形状绘制

enter image description here

我想到了一个背景绘制是正确的,但我无法弄清楚如何实现这一目标。有人有想法吗?

+0

你可以创建一个像这样的9补丁程序,并可以将其设置为你的textview的背景 – mudit 2012-07-16 09:50:08

+0

这实际上是最简单的方法,谢谢。 – FWeigl 2012-07-16 13:36:48

+0

很高兴帮助。 – mudit 2012-07-17 05:26:35

回答

-1

shape.xml(保存在可绘制该文件)

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" > 
    <stroke 
     android:width="1dp" 
     android:color="#000000"/> <!-- This is the Border Color For TextView--> 
<!-- "#5D2E8C" --> 
    <solid android:color="#ffffff" /> <!-- background to the TextView --> 
    <padding 
     android:bottom="2dp" 
     android:left="2dp" 
     android:right="2dp" 
     android:top="2dp" /> 
    <corners android:radius="20dp" /> 

</shape> 

现在,设置背景属性的TextView这样的:

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/shape" 
/> 
0

您可以创建背景用你最喜欢的图像编辑器创建的图像的9-patch图像(它应该很容易做到)或创建一个xml drawable。为了在xml中创建这种类型的drawable,你可以使用ClipDrawable,它会剪切另一个Shape drawable。所以,你将有:

background.xml(这将是TextView的背景):

<?xml version="1.0" encoding="utf-8"?> 
<clip xmlns:android="http://schemas.android.com/apk/res/android" 
    android:clipOrientation="vertical" 
    android:drawable="@drawable/background_shape" 
    android:gravity="bottom" /> 

background_shape.xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" > 

    <corners 
     android:bottomLeftRadius="15dp" 
     android:bottomRightRadius="15dp" /> 

    <solid android:color="#ffffff" /> 

    <padding 
     android:bottom="5dp" 
     android:left="7dp" 
     android:right="7dp" /> 

    <stroke 
     android:width="2dp" 
     android:color="#000000" /> 

</shape> 

然后在你的活动,你会得到该背景可绘制的那个TextView,并设置其级别:

ClipDrawable clip = (ClipDrawable) findViewById(R.id.textView1).getBackground(); 
clip.setLevel(5000); 

您可以通过弯道半径,填充和ClipDrawable的水平打柚木绘制的外观。

我不知道你是否能够用xml drawable获得确切的图像。