Imagebutton full image, round corners

爱⌒轻易说出口 提交于 2019-12-04 07:52:15

I can suggest you to use ImageView instead of ImageButton and catch its onClick().And you can use this xml file to give it a fine black rounded edges outline to your image:

image_bg.xml:(paste this xml file in drawable folder)

<?xml version="1.0" encoding="UTF-8" ?> 
  <shape xmlns:android="http://schemas.android.com/apk/res/android">
  <solid android:color="#000000" /> 
  <stroke android:width="3dp" android:color="#776da8" /> 
  <corners android:bottomRightRadius="5dp" android:bottomLeftRadius="5dp" android:topLeftRadius="5dp" android:topRightRadius="5dp" /> 
  <padding android:left="2dp" android:top="2dp" android:right="2dp" android:bottom="2dp" /> 
  </shape>

You can use it (in xml file where you have added the image) like:

<ImageView android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:id="@+id/image" 
           android:src="@drawable/icon"
           android:background="@drawable/image_bg" /> 

What is the use of the image button? I'm currently working on a soundboard and i ran into the same issue. Then I realized that it doesn't have to be an "imagebutton" for you to be able to use it like a button. Now i'm just using imageview and then using onclick. As for the aesthetics of the black line i don't know but my images have rounded corners because i brought the images in by creating icons under new/other/android icons. It automatically makes one in each diff size category. Hope it helps!

Glenn.nz

I believe this will help you out. You might be able to tweak it slightly to add in black borders when painting the new bitmap.

How to make an ImageView with rounded corners?

You can then just attach an onClick handler to the imageview.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!