【问题标题】:How can I make rounded only one edge of the rectangle?我怎样才能使矩形的只有一个边缘变圆?
【发布时间】:2011-07-29 23:21:06
【问题描述】:

我有以下代码:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
       <stroke android:color="@color/conversation_border" android:width="1dp"/>
       <solid android:color="@color/conversation_is_user_bg"/>
            <corners android:radius="1dp" />
            <padding android:left="7dp" android:top="1dp" android:right="1dp" android:bottom="7dp"/>  
</shape>

当我将它应用到 TextView 时,一切正常。 但是当我替换

<corners android:radius="1dp" />

<corners android:bottomLeftRadius="8dp"
          android:topLeftRadius="0"
          android:topRightRadius="0"
          android:bottomRightRadius="0" />

我有一个例外。 我已经尝试不删除android:radius属性,在px和dp中提供半径,结果总是

error!
UnsupportedOperationException: null

这是非常具有描述性的。 我在做什么错以及如何仅舍入文本视图的左下角?

【问题讨论】:

  • 这是android中的一个bug,这段代码可以在运行2.2或以上版本的android设备上完美运行。
  • android 2.3.3 在模拟器中,r2
  • 我在 android 1.6 设备中遇到了同样的问题,但在 2.2 中完美运行
  • 嗯...我会尝试其他版本,如果它工作正常,我会回复你

标签: android layout android-layout


【解决方案1】:

只留下一个选项:

<corners 
    android:bottomLeftRadius="8dp"
/>

【讨论】:

  • 所以它一定不是形状。你能粘贴堆栈跟踪吗?
【解决方案2】:

试试这个...

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/corners_blue_random">
    <solid android:color="@color/conversation_is_user_bg" />
    <corners android:radius="1dip" android:bottomLeftRadius="8dip"
        android:topLeftRadius="1dip" android:bottomRightRadius="1dip"
        android:topRightRadius="1dip" />
    <stroke android:color="@color/conversation_border"
        android:width="1dp" />
</shape>

【讨论】:

    【解决方案3】:

    这是android模拟器中的一个错误,感谢所有回答的人。 将模拟器更新到最新版本后,一切都无需修改即可工作(例如 this bug ,但有解决方法)

    【讨论】:

      【解决方案4】:

      试试下面的代码:

      <?xml version="1.0" encoding="utf-8"?>
      <shape xmlns:android="http://schemas.android.com/apk/res/android"
          android:shape="rectangle" >
      
          <corners android:bottomLeftRadius="8dip"
              android:topLeftRadius="1dip" android:bottomRightRadius="1dip"
              android:topRightRadius="1dip" />
      
      </shape>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-11-27
        • 1970-01-01
        • 2015-12-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多