我想做一輪Android ImageButton。爲此,我根據link編寫以下代碼。ImageButton背景與XML
在我的main.xml
<?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"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_gravity="center"
android:textColor="#333"
android:textSize="18sp"
android:text="Invite Activity." />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:src="@drawable/round"
android:background="@drawable/roundcorner"
android:padding="50dp" />
</LinearLayout>
在我RES /繪製/ roundcorner.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#33DDFF" />
<corners android:radius="100dp" />
</shape>
但代碼不能正常工作。輸出就像下面
然而,當我在main.xml中
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:src="@drawable/round"
android:background="@drawable/roundcorner"
android:padding="50dp" />
改變的ImageButton到的ImageView它的工作原理如下
我我感到困惑,因爲我知道ImageButton繼承它來自ImageView。爲什麼它的工作方式不同?有沒有什麼辦法解決這一問題?提前致謝!
你可以發佈完整的XML ... –
我已更新完整的xml – pp31630