2011-12-31 3 views
0

XML 레이아웃에서 SurfaceView를 만들 때 표면이 새로 고침 될 때마다 지워진 이유가 있습니다. 그러나 XML을 사용하지 않고 코드에서 초기화하면 그려진 표면이 그대로 유지됩니다.SurfaceView XML로 초기화 됨

나는이 같은 서피스 뷰 SurfaceView를 초기화하면 모든 새로 고침 빈 그려진 : 여기

app = new App(this); 
setContentView(app); 
app.setActivity(this); 

가있다 : 나는 표면의 드로잉마다 새로 고침을 유지이 같은 서피스 뷰 SurfaceView를 초기화하면

app = (App) findViewById(R.id.app); 
app.setActivity(this); 

을 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="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@android:color/black" 
    android:clickable="true"> 
     <com.threedtopo.someapp.android.app 
      android:id="@+id/app" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="@android:color/black" 
      android:clickable="true" /> 
</LinearLayout> 

어떤 통찰력이라도 고맙게 생각합니다!

편집 : 이것은 루트 뷰가 첫 번째 예에서 초기화되는 방식입니다 :이 harism하는

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
     <LinearLayout 
      android:layout_alignParentTop="true" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content"> 
      <!-- <TextView --> 
      <EditText 
      android:id="@+id/hidden_text" 
      android:inputType="textLongMessage" 
      android:autoText="true" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:editable="true" 
      android:visibility="gone" 
      android:focusable="true" 
      android:focusableInTouchMode="true" 
      /> 
     </LinearLayout> 
    <ViewSwitcher 
     android:id="@+id/switcher" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 
     <ImageView 
      android:id="@+id/splash" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/splashscreen" /> 
     <com.threedtopo.someapp.android.app    android:id="@+id/app" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="@android:color/white" 
      android:clickable="true" /> 
    </ViewSwitcher> 
    <LinearLayout 
     android:id="@+id/keyboard_layout" 
     android:layout_alignParentBottom="true" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"> 
     <android.inputmethodservice.KeyboardView 
      android:id="@+id/keyboard" 
      android:visibility="gone" 
      android:focusable="true" 
      android:focusableInTouchMode="true" 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:layout_weight="0" /> 
    </LinearLayout> 
</RelativeLayout> 
+0

차이점에 영향을 줄 수도 있고 미치지 않을 수도 있지만 후자의 경우 루트 요소로 App을 지정하고 배경색을 지정하지 마십시오. – harism

+0

감사의 말, 나는 첫 번째 예제에서 루트 디스플레이가 초기화되는 방법을 추가했다. 모든 XML 레이아웃에서 배경색을 제거하려고 시도했지만 동작을 변경하지 않았습니다. –

+0

확인 - 정확해야합니다. 배경색을 설정하는 것이 범인 인 것처럼 보입니다. 나는 XML 파일의 변경 사항이 내가 깨끗하게 할 때까지 아무 것도하지 않았다고 생각한다. –

답변

0

감사가 해결되었습니다. 분명히 XML 파일에 배경 속성을 설정하면 SurfaceView가 각 그리기를 지 웁니다.