在某些设备Android Studio上不可见ImageButton

发布于 2025-02-04 13:32:18 字数 627 浏览 1 评论 0原文

我在我的Android Studio项目中使用imageButton,并且在我测试了该应用程序的几乎所有设备上都可以看到Image(PNG),但是在我的旧手机上,它是看不见的,但仍然可以单击。这是我的XML代码:

<ImageButton
        android:id="@+id/ib_settings"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_below="@+id/ib_end"
        android:layout_alignParentEnd="true"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="15dp"
        android:background="@null"
        android:scaleType="fitCenter"
        app:srcCompat="@drawable/imgsettings"
        tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />

I use an ImageButton in my android studio project and the image (png) is visible on almost all devices I tested the app, but on my older phone it is invisible, but still clickable tho. This is my xml code:

<ImageButton
        android:id="@+id/ib_settings"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_below="@+id/ib_end"
        android:layout_alignParentEnd="true"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="15dp"
        android:background="@null"
        android:scaleType="fitCenter"
        app:srcCompat="@drawable/imgsettings"
        tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囍笑 2025-02-11 13:32:18

我尝试将不起作用的应用程序:srccompat更改为android:src。然后,我注意到我用作图像源的PNG为2000x2000 PX,如果您想将其调整到40x40dp,那将是很多。因此,我将图像的分辨率更改为600x600 PX,这是解决问题的。

(我在网上任何地方都没有找到这个特定问题的解决方案,所以我决定在这里分享。)

I tried changing app:srcCompat to android:src, which did not work. Then I noticed that the PNG I was using as an image source is 2000x2000 px, which is quite a lot if you want to resize it to 40x40dp. So, I changed the resolution of the image to 600x600 px and that did the trick.

(I didn't find this solution for this specific problem anywhere online, so I decided to share it here.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文