将圆角渲染到无线电组

时间:2016-08-09 09:55:26

标签: android

我使用以下代码创建带圆角的radioGroupButton

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    >
    <RadioGroup
        android:id="@+id/segment_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:layout_gravity="center"
        android:layout_margin="5dip"
        android:checkedButton="@+id/button_one"
        android:orientation="horizontal"
        android:elevation="40dp"
        android:layout_marginTop="10dp"
        android:radius="2dp"
        android:bottomRightRadius="10dp"
        android:bottomLeftRadius="10dp"
        android:topRightRadius="0dp"
        >
        <RadioButton
            android:id="@+id/button_one"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/rbtn_selector"
            android:button="@null"
            android:checked="true"
            android:gravity="center"
            android:padding="5dp"
            android:text="    Pending    "
            android:textColor="@drawable/rbtn_text_selector" />

        <RadioButton
            android:id="@+id/button_two"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/rbtn_selector"
            android:button="@null"
            android:gravity="center"
            android:padding="5dp"
            android:text="    Completed    "
            android:textColor="@drawable/rbtn_text_selector" />
    </RadioGroup>
</LinearLayout>

虽然我提供了android:bottomRightRadius&amp; android:bottomLeftRadius,广播组没有圆角,也没有出现高架。我该如何解决这个问题?

以下是我的可绘制

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

    <item android:state_checked="true" android:color="#ffffffff">
    </item>
    <item android:color="#ff1c5fab"/>

</selector>

1 个答案:

答案 0 :(得分:1)

这是圆角按钮的代码就像这样你也可以用单选按钮。

 <?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle" >
  <corners android:radius="6dp" />
  <gradient
    android:angle="45"
    android:centerColor="@color/color_primary_dark"
    android:centerX="35%"
    android:endColor="@color/color_primary_dark"
    android:startColor="@color/color_primary_dark"
    android:type="linear" />

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

<size
    android:height="60dp"
    android:width="270dp" />

<stroke
    android:width="3dp"
    android:color="@color/color_primary_dark" />