Android 在 SurfaceView 上重叠移动图标

标签 android surfaceview

有人知道如何在 SurfaceView 上重叠移动图标吗? 它就像 Windows 上的光标,但我在 Android 应用程序中需要它。

我尝试使用相对的 ImageView 并不断改变它的位置,但主线程会 ANR。 其次,我尝试将其添加到 Canvas 上,但是当图标移动时它会出现重影,因为我无法清除屏幕。如果我清除屏幕,整个 View 将是黑色的。

有人有这种功能的经验吗?


已解决

将其修复为混合光标和背景颜色,因此我不需要另一个 ImageView 来适应。

最佳答案

在 xml 布局中用 FrameLayout 包围 SurfaceView。然后将您的图标添加到同一个 FrameLayout 中。确保它们放置在表面 View 下方,以便它们绘制在表面 View 之上。

<FrameLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
        <SurfaceView android:id="@+id/surfaceView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></SurfaceView>
        <LinearLayout android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content">
            <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
            <Button android:text="Button" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        </LinearLayout>
    </FrameLayout>

尝试用您的图标或图像替换按钮..

关于Android 在 SurfaceView 上重叠移动图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18626798/

相关文章:

java - threadid=1 : thread exiting with uncaught exception (group=0x4001d5a0)

android - 我可以在使用 gradle 时从 AndroidManifest 中删除 com.google.android.gms.version 吗?

android - Google Map API 无法插入到包含 Google Map Json 的 URL 中

android - 快速暂停/恢复应用程序时 Android NDK 中的 SurfaceView 崩溃

Android GLSurfaceView 通过 MediaPlayer-SurfaceView

android - 如何更改编辑文本的底线颜色?

android - Android 中的圆环按钮

android - 使用 SurfaceView 和 4 个 Canvas 图像如何找到哪个图像被触摸了?

android - 如何将 Canvas 绘图保存为图像?