gpt4 book ai didi

java - 启动应用程序时的空白 View (SurfaceView)

转载 作者:行者123 更新时间:2023-11-29 02:35:10 24 4
gpt4 key购买 nike

当应用程序启动时,我得到一个空白 View 。我可以看到应该在 XML 预览中显示的内容,但是当应用程序启动时它只是白色的。我可以看到 SurfaceView 的轮廓,但它没有内容。

我是自学的,所以基础知识有限,想理解答案,所以非常感谢简短的解释!

谢谢 - Frenchie。

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<com.Frenchie.SurfaceView.MySurfaceView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="0dip"
android:id="@+id/surfaceView"/>

</LinearLayout>

主 Activity

package com.Frenchie.SurfaceView;

import ...

public class MainActivity extends Activity {

com.Frenchie.Drawing.MySurfaceView surfaceView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

surfaceView = findViewById(R.id.surfaceView);
}
}

MySurfaceView

package com.Frenchie.SurfaceView;

import ...

public class MySurfaceView extends SurfaceView implements Runnable {
private Bitmap bmp;
private SurfaceHolder holder;

public MySurfaceView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
holder = getHolder();
holder.addCallback(new SurfaceHolder.Callback() {

@Override
public void surfaceCreated(SurfaceHolder holder) {
Canvas c = holder.lockCanvas(null);
draw(c);
holder.unlockCanvasAndPost(c);
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
}
});
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.player);
}

@Override
public void draw(Canvas canvas) {
super.draw(canvas);


canvas.drawColor(Color.BLACK);
canvas.drawBitmap(bmp, (MeasureSpec.getSize(getMeasuredWidth()) - bmp.getWidth())/2, (MeasureSpec.getSize(getMeasuredHeight()) - bmp.getHeight())/2, null);
}

@Override
public void run() {
//TODO movement here when display is working
}
}

逻辑猫

11-27 16:20:43.437 24092-24092/? I/zygote: Not late-enabling -Xcheck:jni (already on)
11-27 16:20:43.450 24092-24092/? W/zygote: Unexpected CPU variant for X86 using defaults: x86
11-27 16:20:43.804 24092-24092/com.Frenchie.SurfaceView I/InstantRun: starting instant run server: is main process
11-27 16:20:43.948 24092-24110/com.Frenchie.SurfaceView D/OpenGLRenderer: HWUI GL Pipeline

[ 11-27 16:20:44.001 24092:24110 D/ ]
HostConnection::get() New Host Connection established 0xa4329740, tid 24110


[ 11-27 16:20:44.005 24092:24110 W/ ]
Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1
11-27 16:20:44.011 24092-24110/com.Frenchie.SurfaceView I/zygote: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
11-27 16:20:44.011 24092-24110/com.Frenchie.SurfaceView I/OpenGLRenderer: Initialized EGL, version 1.4
11-27 16:20:44.011 24092-24110/com.Frenchie.SurfaceView D/OpenGLRenderer: Swap behavior 1
11-27 16:20:44.013 24092-24110/com.Frenchie.SurfaceView D/EGL_emulation: eglCreateContext: 0xa43328a0: maj 2 min 0 rcv 2
11-27 16:20:44.018 24092-24110/com.Frenchie.SurfaceView D/EGL_emulation: eglMakeCurrent: 0xa43328a0: ver 2 0 (tinfo 0xaeb325d0)
11-27 16:20:44.104 24092-24110/com.Frenchie.SurfaceView D/EGL_emulation: eglMakeCurrent: 0xa43328a0: ver 2 0 (tinfo 0xaeb325d0)
11-27 16:20:45.783 24092-24092/com.Frenchie.SurfaceView V/StudioProfiler: StudioProfilers agent attached.
11-27 16:20:45.828 24092-24158/com.Frenchie.SurfaceView V/StudioProfiler: Acquiring Application for Events
11-27 16:20:45.849 24092-24092/com.Frenchie.SurfaceView V/StudioProfiler: Transformed class: java/net/URL
11-27 16:20:45.851 24092-24092/com.Frenchie.SurfaceView W/zygote: Current dex file has more than one class in it. Calling RetransformClasses on this class might fail if no transformations are applied to it!
11-27 16:20:46.312 24092-24092/com.Frenchie.SurfaceView V/StudioProfiler: Memory control stream started.
11-27 16:20:46.826 24092-24167/com.Frenchie.SurfaceView V/StudioProfiler: Live memory tracking disabled.
11-27 16:20:46.828 24092-24167/com.Frenchie.SurfaceView V/StudioProfiler: Live memory tracking enabled.
11-27 16:20:46.828 24092-24167/com.Frenchie.SurfaceView V/StudioProfiler: JNIEnv not attached
11-27 16:20:47.012 24092-24167/com.Frenchie.SurfaceView V/StudioProfiler: Loaded classes: 5094
11-27 16:20:47.416 24092-24167/com.Frenchie.SurfaceView V/StudioProfiler: Tracking initialization took: 588509880ns

如果您需要更多信息,请随时告诉我。

最佳答案

当我在我的 S6 而不是模拟设备上运行程序时,这个问题得到了解决...不知道为什么,但在这种情况下它解决了这个问题。

关于java - 启动应用程序时的空白 View (SurfaceView),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47511368/

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