问题描述
嗯..我在我的Android应用程序的一些ImageButtons。我希望他们能够显示完整的画面。我的意思是:我想要的ImageButton是公正的图片,你知道
Well.. I have some ImageButtons in my Android application. I want them to display the full picture. I mean: I want the ImageButton to be JUST the picture, you know?
好吧......到目前为止,这么好......我能做到这一点使用属性背景。
Ok... so far, so good... I can do it use the property "background".
不过,我也想了的ImageButton有边角圆润。
However I also want the ImageButton to have the corners rounded.
我有下面的XML在我的布局文件夹:
I have the following xml in my layout folder:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFFFF"/>
<corners android:radius="10dip"/>
<stroke android:width="8dip"/>
<size android:height="8dip"/>
</shape>
它的工作原理完美的,当我不想要的图片,以填补整个ImageButton的......但是当我尝试使用图片使用整个的ImageButton ...它不显示圆角。
It works perfect when I don't want the picture to fill the WHOLE ImageButton... however when I try to use the picture to use the whole imagebutton... it doesn't show the rounded corners.
谁能帮我,好吗?
奖金的问题:此外,我怎么能有一个美丽的黑线(圆角)周围的ImageButton?
Bonus question: Also, how can I have a beautiful black line (rounded corners) around the imagebutton?
推荐答案
我可以建议你使用,而不是ImageButton的ImageView的,赶上它的onClick()。你可以使用这个xml文件给它一条黑色的精致圆润的边角轮廓你的形象:
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:(粘贴绘制文件夹此XML文件)
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>
您可以使用它(在您添加了图像的xml文件),如:
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" />
这篇关于的ImageButton完整的图像,圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!