有人知道如何在 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/