2012-07-16 75 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獲得確切的圖像。