2015-05-19 121 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>