2015-05-19 156 views
-1

我需要創建一個文本視圖,只有 TopLeft和TopRight圓錐體,沒有其他人, 我已經爲4個圓角寫了一個XML,但它不支持兩個圓角。 這裏是XML如何在android中只創建兩個邊緣圓角的textView?

<?xml version="1.0" encoding="utf-8"?> 
<!-- res/drawable/rounded_edittext.xml --> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" android:padding="10dp"> 
    <solid android:color="#FFFFFF"/> 
    <corners 
     android:bottomRightRadius="5dp" 
     android:bottomLeftRadius="5dp" 
     android:topLeftRadius="5dp" 
     android:topRightRadius="5dp"/> 
</shape> 

任何建議或幫助..?

+0

這可能有助於http://www.gadgetsaint.com/tips/rounded-corners-views-layouts-android/#.WPz2QVN97BI – ASP

回答

2

從你提供的代碼中,你只是實現你想要的一步。

<?xml version="1.0" encoding="utf-8"?> 
<!-- res/drawable/rounded_edittext.xml --> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" android:padding="10dp"> 
    <solid android:color="#FFFFFF"/> 
    <corners 
     android:bottomRightRadius="5dp" 
     android:bottomLeftRadius="5dp" 
     android:topLeftRadius="5dp" 
     android:topRightRadius="5dp"/> 
</shape> 

您可以註釋掉android:bottomRightRadius="5dp"android:bottomLeftRadius="5dp",並添加android:radius="0dp",或者將它們設置爲0dp。所以結果可能是:

<?xml version="1.0" encoding="utf-8"?> 
<!-- res/drawable/rounded_edittext.xml --> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" android:padding="10dp"> 
    <solid android:color="#FFFFFF"/> 
    <corners 
     android:radius="0dp" 
     android:topLeftRadius="5dp" 
     android:topRightRadius="5dp"/> 
</shape> 
+0

jyoon,我試過了,但沒有顯示預覽,我也要檢查調試,並對此發表評論。 –

+0

jyoon,謝謝......它的工作....需要運行它。謝謝.... –

+1

這只是IDE的一個bug。預覽渲染非常糟糕。另外,如果它有幫助,接受我的答案。 – jyoon

0

嘗試使用以下xml

<?xml version="1.0" encoding="utf-8"?> 
    <selector xmlns:android="http://schemas.android.com/apk/res/android"> 
     <item> 
     <shape xmlns:android="http://schemas.android.com/apk/res/android"> 
      <stroke android:width="2dp" android:color="@color/grey" /> 
      <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> 
      <corners android:topLeftRadius="5dp" android:topRightRadius="5dp"/> 
     </shape> 
     </item> 
    </selector>