gpt4 book ai didi

java - Android 图像按钮不显示

转载 作者:行者123 更新时间:2023-12-02 10:40:47 24 4
gpt4 key购买 nike

图像按钮没有显示在我的应用程序中,但该按钮仍然可点击,其点击日志有效。

这是按钮:

<ImageButton
android:id="@+id/stopStream"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="10dp"
android:background="@drawable/cancel_btn"
android:contentDescription="@string/stop_stream"
android:onClick="hangup"
android:visibility="visible" />

Android Studio 确实显示了可绘制图标和左侧工具栏,因此图像的路径是正确的。首先我想到了 z-index 错误(我来自网络世界)。但据我所知,android 中并没有真正的 z-index 来给出标签。什么可能进一步导致此问题

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
tools:context="de.app.test.VideoChatActivity">

<android.opengl.GLSurfaceView
android:id="@+id/gl_surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />

<ImageButton
android:id="@+id/stopStream"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="10dp"
android:background="@drawable/cancel_btn"
android:contentDescription="@string/stop_stream"
android:onClick="hangup"
android:visibility="visible" />

<ImageButton
android:id="@+id/switchCameraBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignTop="@+id/stopStream"
android:layout_marginEnd="9dp"
android:background="@color/transparent"
android:contentDescription="@string/send"
android:visibility="gone" />

<ImageButton
android:id="@+id/switchBtn"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_alignTop="@+id/switchCameraBtn"
android:layout_marginEnd="9dp"
android:background="@drawable/call_btn"
android:contentDescription="@string/send" />

<RelativeLayout
android:id="@+id/drawable_mod"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone">

<ImageView
android:id="@+id/drawing1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:contentDescription="@string/drawing_one" />

</RelativeLayout>

</RelativeLayout>

最佳答案

尝试使用 src 将图标设置为 ImageButton,例如

<ImageButton
android:id="@+id/stopStream"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="10dp"
android:src="@drawable/cancel_btn"
android:background="@null"
android:contentDescription="@string/stop_stream"
android:onClick="hangup"
android:visibility="visible" />

//used background="@null" to set the image button background as null to only show the icon which was set with the src.

关于java - Android 图像按钮不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52930408/

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