2016-09-24 94 views
0

我试图获得圆形图像按钮。但它正在显示带有方形背景的圆形图像,但我只需要没有任何背景的图像。 我也使用round_image.XML作为背景可绘制文件,但它不工作。如何获得Android工作室的圆形图像按钮

menu.xml文件

<ImageButton 
android:id="@+id/imageButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true"  android:src="@drawable/sliderr" android:background="@drawable/round_image"/> 

round_image.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"> 
<gradient android:startColor="#50d050          
android:endColor="#008000" android:angle="270"/> 
<stroke 
android:width="1px" 
android:color="#000000"/> 
</shape> 
+0

你尝试过这个http://stackoverflow.com/问题/ 9884202 /定制圆形按钮 –

+0

是啊!但我没有使用状态按下和重点。我曾尝试使用选择器。 –

+0

Possilble重复的:http://stackoverflow.com/questions/21397115/rounded-image-button-android –

回答

0

使用这个角落,而不是你的

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <solid android:color="@color/colorPrimary" /> 
    <stroke android:color="@color/colorPrimary" /> 
    <corners 
     android:bottomLeftRadius="5dp" 
     android:bottomRightRadius="5dp" 
     android:topLeftRadius="5dp" 
     android:topRightRadius="5dp" /> 
</shape> 
+0

我也试过,但它不工作 –

+0

我认为你使用的图像src,所以你设置的背景将被覆盖图片src @RohithaAgina –