2016-12-31 1 views
1

OpenGL을 처음 접했을 때 내 문제가 발생했습니다. SetContentView("R.layout.main") 아무 작업도 수행되지 않지만 SetContentView("mGLView") 게임이 정상적으로 표시됩니다. 내 main.xml 파일에는 표면보기가 포함되어 있으므로 main.xml에는 표면보기가 있기 때문에 표시 될 것이라고 생각했습니다.OpenGL ES 2 : SetContentView가 XML 파일로 설정된 경우 GLSurface 뷰

이 문제를 해결하는 방법은 의심 스럽지만 addview 또는 findviewbyid를 사용하여 해결할 수 있습니다.

와 관계있는 MainActivity 코드 :

public class OpenGLES20Activity extends Activity { 
private GLSurfaceView mGLView; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    mGLView = new MyGLSurfaceView(this); 
    setContentView(R.layout.main); 

main.xml에 코드 :

<FrameLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <RelativeLayout android:id="@+id/linearLayout1" android:layout_width="wrap_content" 
android:layout_height="wrap_content"> 

      <SurfaceView 
android:id="@+id/SurfaceView" 
android:layout_width="500dp" 
android:layout_height="478dp"> 
</SurfaceView> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/Timer" 
       android:id="@+id/Timer"/> 
     </RelativeLayout> 

    </FrameLayout> 

어떤 도움에 감사드립니다.

답변

0

당신은 당신의 그래서 그냥 SurfaceViewcom.example.yourapp.MyGLSurfaceView에 변경 대신 SurfaceView XML 파일의 GLSurfaceView 확장 설정해야합니다 : 내 코드에서 변경 한

<com.example.yourapp.MyGLSurfaceView 
    android:id="@+id/SurfaceView" 
    android:layout_width="500dp" 
    android:layout_height="478dp"/> 
+0

지금은 오류 오류 다음 한 : (31, 19) 오류 : MyGLSurfaceView 클래스의 생성자 MyGLSurfaceView는 주어진 유형에 적용 할 수 없습니다. 필수 : ​​Context, AttributeSet found : 인수 없음 이유 : 실제 및 형식 인수 목록의 길이가 다릅니다 – DarkEnergy

+0

생성자가 연결된 문서에 표시된 것처럼 MyGLSurfaceView (컨텍스트 컨텍스트, AttributeSet attrs) 여야합니다. – MarGenDo

+0

내 생성자가 그것에 설정되어 있고 오류가 계속 발생합니다. 이것이 도움이된다면 IDE에서 문제가 있음을 나타냅니다 : mGLView = new MyGLSurfaceView (this); – DarkEnergy