2012-01-13 3 views
2

アクティビティがあり、アクティビティのコンテンツビューを "R.layout.main.xml"として設定していました。また、OpenGLを使用して作成したアニメーションを含む別のクラスがあります。今私はアクティビティのバックグラウンドでこのアニメーションを使用する必要があります。アクティビティでGlSurfaceviewを使用

コードは、この

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.main_pixie); 

    mGLView = new ClearGLSurfaceView(this); 
    setContentView(mGLView); 
} 

のようなものですが、私はこの問題を解決することができます私のアプリは..Howをクラッシュされます。

答えて

3

setContentView()をもう一度呼び出すと、最初に設定したものが置き換えられ、背景のみが残されます。クラッシュは主レイアウトの要素に依存しているために発生している可能性があります。

setContentView()を2回呼び出すのではなく、GLSurfaceViewをメインレイアウトに含める必要があります。以下は、これを行う方法の例は次のとおりです。

<?xml version="1.0" encoding="UTF-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent> 
    <your.application.package.ClearGLSurfaceView 
     android:layout_width="match_parent" 
     android:layout_width="match_parent"/> 
    <!--put the rest of your layout here, i.e the contents of the original R.layout.main_pixie--> 
</FrameLayout> 

が次にあなたがmain_pixie_new(いつものようにonCreate()は、上記のXMLを指し、あなたにこのレイアウトをロードすることができ、私はちょうどそれを可能な限り明確なようなものを維持するためにその名前を与えました):

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.main_pixie_new); 
} 
関連する問題