试图GLSurfaceView添加到布局编程

试图GLSurfaceView添加到布局编程

本文介绍了试图GLSurfaceView添加到布局编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,只是一些背景......我有一个使用画布绘制一个全功能的游戏,我在努力学习并转换图纸交给的OpenGL ES 1.0的过程。 (保持兼容。)

Ok, Just some background... I have a fully functioning game that uses the canvas to draw, and I'm in the process of trying to learn and convert the drawing over to OpenGL ES 1.0. (to keep compatibility.)

我一直在努力做的,就是找出一种方法,以纳入GLSurfaceView和渲染到程序中,这样我可以一块切换绘图在一块。 (有很多精灵,我有需要经常更新,所以我不希望它带我一个月的发布一次更新。)

What I've been trying to do, Is figure out a way to incorporate the GLSurfaceView and Renderer into the program so that I can switch the drawing over piece by piece. (There are a lot of sprites and I have needs to update often, so I don't want it to take me a month to release the next update.)

有人建议我使用GLSurfaceView在当前SurfaceView的顶部,我到达那里,但我已经遇到了障碍。

It has been suggested that I Use the GLSurfaceView on top of the current SurfaceView, and i'm getting there but I've hit a snag.

我基本上使用LunarLander例子,尝试添加一个简单的OpenGL渲染绘制纹理一个正方形,并​​呈现它。这样做的目的是绘制在画布上方的广场上。

I'm basically using the LunarLander example and trying to add on a simple OpenGL renderer that draws a texture on a square and renders it. The goal would be to draw the square on top of the canvas.

下面是相关code在活动:

Here is the relevant code in the Activity:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



        setContentView(R.layout.lunar_layout);


        LinearLayout detailListView = (LinearLayout) findViewById(R.id.dets); // Find the layout where you want to add button

    Button button = new Button(this);
    button.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT));
    detailListView.addView(button);//add view to add



    mGLSV = new BasicGLSurfaceView(this);
    mGLSV.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT));
    detailListView.addView(mGLSV);

    //clipped

该lunar_layout文件看起来是这样的:

The lunar_layout file looks like this:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

    android:layout_width="match_parent"
    android:layout_height="match_parent">



    <com.example.android.lunarlander.LunarView
        android:id="@+id/lunar"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/>

    <LinearLayout
       android:id="@+id/dets"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignParentLeft="true"
       android:layout_alignParentTop="true"
       android:layout_marginLeft="0dp"
       android:layout_marginTop="50dp"
       android:orientation="vertical" >

         <com.google.ads.AdView
             android:id="@+id/adView"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             ads:adSize="BANNER"
             ads:adUnitId="a14ecf8f2d9ef49"
             ads:loadAdOnCreate="true" >
         </com.google.ads.AdView>

    </LinearLayout>



     <RelativeLayout
         android:id="@+id/relLayout"
         android:layout_width="match_parent"
         android:layout_height="match_parent" >

         <TextView
             android:id="@+id/text"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_centerInParent="true"
             android:gravity="center_horizontal"
             android:text="@string/lunar_layout_text_text"
             android:textColor="#88ffffff"
             android:textSize="24sp"
             android:visibility="visible" />

      </RelativeLayout>

</FrameLayout>

pretty的简单,我想使用的LinearLayout添加的东西在表面观之上。请注意,我还添加了一个从无到有按钮,只是为了检查的概念作品。什么我最终是画布,按钮显示正确,但GLSurfaceView的迹象。我究竟做错了什么?

Pretty Simple, I'm trying to use that LinearLayout to add things on top of the Surface View. Notice I also add a scratch Button, just to check the concept works.What I end up with is the canvas, and the button showing up correctly, but no sign of the GLSurfaceView. What am I doing wrong?

推荐答案

想通了自己。尽管SurfaceView是View的子类,SurfaceView显示通过窗口的方式是有点滑稽,基本上画布实际上穿过surfaceview,但它背后的Z顺序。这个多面的,因为意见必须使用surfaceview.setZOrderOnTop(真)进行排序;

Figured it out myself. Even though SurfaceView is a subclass of View, the way SurfaceView displays through the window is kinda funny, Basically The canvas actually goes through the surfaceview but is behind it in Z order. Because of this Multiple surface views have to be ordered using surfaceview.setZOrderOnTop(true);

现在我只担心使得GLSurfaceView透明。

Now I just have to worry about making the GLSurfaceView Transparent.

这篇关于试图GLSurfaceView添加到布局编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:53