gpt4 book ai didi

android - Imagebutton 完整图像,圆角

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:01:05 25 4
gpt4 key购买 nike

嗯.. 我的 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 时......它不显示圆角。

有人能帮帮我吗?

奖金问题:另外,我怎样才能在图像按钮周围有一条漂亮的黑线(圆角)?

最佳答案

我可以建议您使用 ImageView 而不是 ImageButton 并捕获它的 onClick()。您可以使用此 xml 文件为其图像提供精细的黑色圆边轮廓:

image_bg.xml:(将此 xml 文件粘贴到 drawable 文件夹中)

<?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 文件中):

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

关于android - Imagebutton 完整图像,圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8032301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com