Imagebutton 完整图像,圆角
嗯..我的 Android 应用程序中有一些 ImageButtons。我希望他们展示完整的图片。我的意思是:我希望 ImageButton 只是图片,你知道吗?
好的...到目前为止,一切顺利...我可以使用“背景”属性来做到这一点。
不过我也希望 ImageButton 的角是圆角的。
我的布局文件夹中有以下 xml:
<?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 时...它不显示圆角。
有人可以帮我吗?
额外问题:另外,如何在图像按钮周围有一条漂亮的黑线(圆角)?
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".
However I also want the ImageButton to have the corners rounded.
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>
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.
Can anyone help me, please?
Bonus question: Also, how can I have a beautiful black line (rounded corners) around the imagebutton?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
图片按钮有什么用?我目前正在开发音板,遇到了同样的问题。然后我意识到它不必是一个“图像按钮”,您就可以像按钮一样使用它。现在我只是使用 imageview,然后使用 onclick。至于黑线的美观,我不知道,但我的图像有圆角,因为我通过在新/其他/Android 图标下创建图标来引入图像。它会自动在每个差异大小类别中创建一个。希望有帮助!
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!
我相信这会对你有所帮助。您可以稍微调整它以在绘制新位图时添加黑色边框。
如何制作带有圆角的 ImageView?
然后可以将 onClick 处理程序附加到 imageview。
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.
我可以建议您使用 ImageView 而不是 ImageButton 并捕获其 onClick()。您可以使用此 xml 文件为您的图像提供精细的黑色圆角轮廓:
image_bg.xml:(粘贴这个 xml 文件位于可绘制文件夹中)
您可以使用它(在添加图像的 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:(paste this xml file in drawable folder)
You can use it (in xml file where you have added the image) like: