ImageButton圆角不起作用

时间:2016-02-18 22:42:02

标签: android xml


在XML预览中,我有ImageButtons的圆角,但如果我启动模拟器或我的设备,我没有圆角。

什么原因?希望得到一些帮助。

roundedcorner.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="?android:colorAccent" />
    <corners android:radius="5dp" />
</shape>

activity_main.xml中

<LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent" >
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageButtonOne"
        android:src="@drawable/one"
        android:background="@drawable/roundedcorner"
        android:layout_weight="1" />
    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageButtonTwo"
        android:src="@drawable/two"
        android:background="@drawable/roundedcorner"
        android:layout_weight="1"
        android:layout_marginLeft="20dp" />
</LinearLayout>

仿真器:
Emulator:  
前瞻:
Preview:

1 个答案:

答案 0 :(得分:0)

将roundedcorner.xml更改为;

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <solid android:color="?colorAccent" />
    <corners android:radius="5dp" />
</shape>

并设置为ImageButton

的背景
<LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent" >

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageButtonOne"
        android:src="@drawable/one"
        android:background="@drawable/roundedcorner"
        android:layout_weight="1" />

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageButtonTwo"
        android:src="@drawable/two"
        android:background="@drawable/roundedcorner"
        android:layout_weight="1"
        android:layout_marginLeft="20dp" />

</LinearLayout>

当你的意思是@drawable/roundcorner时,请注意拼写错误@drawable/roundedcorner

相关问题