기본 SurfaceView에 조각을 어떻게 추가합니까? 나는 예외를 얻을기본 SurfaceView에 조각 추가
java.lang.IllegalArgumentException: No view found for id 0x7f0b0050
나는 ... 이것이 내가 정의 서피스 뷰 SurfaceView에 대한 참조를 설정 같은
대신setContentView(R.layout.activity_main);
된 setContentView의 모든 레이아웃을 설정하지 않는 때문에 생각
final GameSurface gs = new GameSurface(this);
setContentView(gs);
다음 표면 뷰 콜백 ontouch (...) - 사용자가 표면을 클릭하면 조각이로드됩니다.
사전에 363,210@Override
public boolean onTouchEvent(MotionEvent event) {
.....
FragmentManager fragmentManager =((Activity)context).getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
ExchangeFragment fragment = new ExchangeFragment();
fragmentTransaction.add(R.id.relLayout, fragment);
fragmentTransaction.commit();
감사
편집 :
없음 충돌 더 이상하지만 조각 실 거예요 표시됩니다. 왜? @Kelevandos 덕분에 다른 스택 스레드
How to inflate one view with a layout
의 대답은, 나는 사용자 정의 surfaceViews 생성자에 AttributSet을 추가 HADE.
무엇이 누락 되었습니까? 다음은 XML 파일
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<se.brickgame.brickbreaker.GameSurface
android:id="@+id/surfaceId"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<RelativeLayout
android:id="@+id/relLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</RelativeLayout>
편집은 2 :
나는 또한 코드fragmentManager.executePendingTransactions();
System.out.println("FRAGMENT ISADDED = " + fragment.isAdded());
System.out.println("FRAGMENT VISIBLE = " + fragment.isVisible());
System.out.println("FRAGMENT HIDDEN = " + fragment.isHidden());
System.out.println("FRAGMENT ISINLAYOUT = " + fragment.isInLayout());
이 추가 다음과 같은 결과를 얻었다
11-25 16:09:07.957 12155-12155/se.brickgame.brickbreaker ISystem.out: FRAGMENT ISADDED = true
11-25 16:09:07.957 12155-12155/se.brickgame.brickbreaker I/System.out: FRAGMENT VISIBLE = true
11-25 16:09:07.957 12155-12155/se.brickgame.brickbreaker I/System.out: FRAGMENT HIDDEN = false
11-25 16:09:07.957 12155-12155/se.brickgame.brickbreaker I/System.out: FRAGMENT ISINLAYOUT = false
그래서 .. 거기에있는 것 같다. 레이아웃에 없다 - 어떻게 해석 할까?
감사하지만 조각이 나타나지 않습니다. 나는 지금 그것을 이해할 수 없다, 편집을 참조하십시오. – java
이 답변으로 많은 도움이되었습니다. – java