启动应用程序时空白视图(SurfaceView)



启动应用程序时,我会得到空白的视图。我可以看到XML预览中应该显示的内容,但是当应用程序启动时,它只是白色。我可以看到表面视图的轮廓,但是没有内容。

我是自学的,因此基本知识是有限的,并且想了解回答,因此将非常感谢!

谢谢 - 法国人。

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>

MainActivity

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
    }
}

logcat

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上运行程序而不是模拟设备时,解决了此问题...不确定为什么但是在这种情况下,它解决了问题。

相关内容

  • 没有找到相关文章

最新更新