圆角磨边

时间:2011-10-26 09:38:38

标签: android android-layout

我想创建自定义按钮,其中包含圆角 右下角 右上角 角。

但是,我将 左下角 右上角 舍入,但我的实现似乎没问题。

我做错了什么?

我使用存储在drawable文件夹中的以下形状定义:

button_shape.xml

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

  <solid android:color="#F66622"/>
  <padding 
    android:left="5dip"
    android:top="5dip"
    android:right="5dip"
    android:bottom="5dip"
  />
  <corners
    android:radius="20dip"
    android:bottomLeftRadius="0dip"
    android:topLeftRadius="0dip"
  />
</shape>

,布局文件是这样的:

main.xml中

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bg"
    >
    <Button 
        android:id="@+id/btnFoo"
        android:text="@string/btn_foo_title"
        android:background="@drawable/button_shape"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dip"
        android:layout_centerInParent="true"
        android:textSize="26sp"
    />
</RelativeLayout>

结果如下:

messed corners http://img715.imageshack.us/img715/5954/corners.png

我还尝试在button_shape文件中单独定义每个角半径

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

......结果相同。

这个功能是否有可能在Android SDK中被搞砸了?

1 个答案:

答案 0 :(得分:2)

愚蠢的问题,但你是否尝试围绕bottomLeft并看看它是否绕着右下角?我知道这不是一个真正的解决方案,但解决方案也很好。如果它看起来像你想要的那样,那么你如何实现它并不重要。

相关问题