2012-10-09 30 views
9

strong text我想圍繞文本視圖的唯一一側,如左上角的圓和 右上角的圓,我使用此代碼。但它不會工作。如何在android中對文本視圖的一角進行圓角修改

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

<solid android:color="@color/login_layout" /> 

<stroke 
     android:width="1dp" 
     android:color="@color/login_layout" /> 

<padding 
     android:bottom="1dp" 
     android:left="1dp" 
     android:right="1dp" 
     android:top="1dp" /> 

<corners 
     android:bottomLeftRadius="0dip" 
     android:bottomRightRadius="0dip" 
     android:topLeftRadius="10dip" 
     android:topRightRadius="10dip" /> 

</shape> 

回答

8

有時它不會顯示在仿真器和圖形佈局 嘗試在真實設備上運行的代碼,並檢查

+0

它顯示與新的Android Sutdio 2.3。+ – blueware

3

請試試這個方式..

texttextshape。 xml文件。

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

    android:shape="rectangle" > 

    <solid android:color="#FFFFFF" /> 
    <corners 
     android:bottomLeftRadius="5dp" 
     android:bottomRightRadius="5dp" 
     android:topLeftRadius="5dp" 
     android:topRightRadius="5dp" 
     /> 

</shape> 

和設置Text_view機器人:背景= 「@繪製/ texttextshape」

我認爲它幫助你..

1

使繪製文件夾一個XML ..假設round.xml。然後編輯它如下。

<?xml version="1.0" encoding="UTF-8"?> 
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <stroke android:width="1dip" android:color="#A6A6A6" /> 
    <solid 

     android:color="#ffffff" 
     /> 
    <corners 
     android:topLeftRadius="15px" 
     android:bottomLeftRadius="15px" 
     /> 

    <padding 
    android:top="3dp" 
    android:bottom="3dp" 
    /> 
</shape> 

然後在textview的背景設置此xml。

4

變化,

<corners 
    android:bottomLeftRadius="0dip" 
    android:bottomRightRadius="0dip" 
    android:topLeftRadius="10dip" 
    android:topRightRadius="10dip" /> 

<corners 
    android:radius="5dip" 
    android:bottomLeftRadius="0dip" 
    android:bottomRightRadius="0dip" 
    android:topLeftRadius="10dip" 
    android:topRightRadius="10dip" /> 

其實這是Android的一個bug,你必須明確地將其他的半徑值之前,需要手動設置radius屬性一些隨機值。

2

最簡單的解決方案是製作一個圓角的圖像,並將其設置爲textView的背景。