【问题标题】:Why does button look weird?为什么按钮看起来很奇怪?
【发布时间】:2016-04-04 00:03:56
【问题描述】:

我正在尝试制作这样的按钮:

这就是它在我的 XML 布局编辑器中的显示方式,我希望它在我的模拟器中也能这样显示。但是,在我的实际模拟器和测试设备中看起来像这样:

为什么不四舍五入?我怎样才能使它更圆润?这是我的按钮:

    android:onClick = "messageButton"

    android:text="Make Custom Message"
    android:textColor="#FFFFFF"
    android:textSize="15sp"

    android:layout_width="230dp"
    android:layout_height="63dp"
    android:background="@drawable/messagebutton"
    android:shadowColor="#A8A8A8"
    android:shadowDx="0"
    android:shadowDy="0"
    android:shadowRadius="5"
    android:layout_above="@+id/helpbutton2"
    android:layout_centerHorizontal="true" />

这里是drawable:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <corners
        android:topLeftRadius="100dp"
        android:topRightRadius="100dp"
        android:bottomLeftRadius="100dp"
        android:bottomRightRadius="100dp"
        />
    <gradient
        android:angle="45"
        android:centerX="35%"
        android:centerColor="#A871A6"
        android:startColor="#E8E8E8"
        android:endColor="#33FF8B"
        android:type="linear"
        />
    <padding
        android:left="0dp"
        android:top="0dp"
        android:right="0dp"
        android:bottom="0dp"
        />
    <size
        android:width="250dp"
        android:height="83dp"
        />
    <stroke
        android:width="3dp"
        android:color="#878787"
        />
</shape>

谢谢,

鲁基尔

【问题讨论】:

  • topLeftRadius="100dp" 半径很大。试试小一点的
  • @njzk2 非常感谢,已经解决了。随意留下答案,我会接受的。但是,为什么减小半径可以解决它?

标签: java android xml string algorithm


【解决方案1】:

圆角矩形半径如下图所示。您需要将半径设置为按钮高度的一半,即 63/2=~32dp

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多