我正在尝试制作圆形的Android ImageButton。为此,我根据link编写以下代码。
在我的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 / drawable / 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
中将 ImageButton 更改为 ImageView 时<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。为什么它的工作方式不同?有没有什么办法解决这一问题?提前谢谢!
答案 0 :(得分:0)
让你的src成为android:src =“@ drawable / roundcorner”,或者让它透明,这样你就可以看到背后的圆形背景。