【问题标题】:android:topLeftRadius overriding other cornersandroid:topLeftRadius 覆盖其他角
【发布时间】:2013-09-18 23:52:20
【问题描述】:

解决方案: 好吧,它是我的模拟器和 Eclipse 布局编辑器。在真正的手机上它工作得很好:(

问题:

用于角的 android:topLeftRadius 覆盖了 topRight、bottomRight 和 bottomLeft。

所以虽然我希望右侧是圆形的,但左侧应该是方形的,但两边都是方形的。

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

<solid android:color="#F000" />

<stroke
    android:width="1px"
    android:color="#BB000000" />

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

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

<gradient
    android:angle="90"
    android:centerColor="#00004C"
    android:endColor="#000099"
    android:startColor="#000000"
    android:type="linear" />

</shape>

我只是在一个按钮的 xml 中调用它。

android:background="@drawable/button_layout"

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    您忘记了您的属性周围需要&lt;shape&gt;。这段代码对我有用:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
      <solid android:color="#F000" />
    
      <stroke
         android:width="1px"
         android:color="#BB000000" />
    
      <padding
         android:bottom="7dp"
         android:left="10dp"
         android:right="10dp"
         android:top="7dp" />
    
      <corners
         android:bottomLeftRadius="0dp"
         android:bottomRightRadius="10dp"
         android:topLeftRadius="0dp"
         android:topRightRadius="10dp" />
    
      <gradient
         android:angle="90"
         android:centerColor="#00004C"
         android:endColor="#000099"
         android:startColor="#000000"
        android:type="linear" />
    
    </shape>
    

    【讨论】:

    • 你忘记在你的参数周围加上一个```。我编辑了我的答案。
    • 对不起,这是一个复制和粘贴错误,然后堆栈踢了标签。我确实拥有它并编辑了我的帖子
    • 就像我说的:对我来说它正在工作。也许还有其他一些因素?
    • 我建立了一个新项目,只有一个 textview 按钮和这个布局,但它仍然无法正常工作。在 4.3 上构建 2.2 我想知道是不是这样。
    【解决方案2】:

    这可能与 3.0 之前的 Android 版本中的错误有关(请参阅https://code.google.com/p/android/issues/detail?id=9161

    您可以通过为不同的 api 版本设置单独的可绘制文件夹来解决它。

    另见Something's wrong in Corner radius Android

    【讨论】:

    • 是的,我读过这个并且必须使用它,但这不是这里发生的事情。但是谢谢它确实有帮助
    猜你喜欢
    • 2020-09-15
    • 2015-05-14
    • 2020-10-06
    • 2016-09-13
    • 1970-01-01
    • 2023-03-17
    • 2020-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多