2015-01-15 2 views
1

저는 실제로 Google Maps API를 사용하는 Android 앱을 프로그래밍하고 있습니다.펼치기 조각으로 된 레이아웃의 ViewGroup

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:id="@+id/mapContainer" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       tools:context=".MainActivity" > 

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:map="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/map" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:name="com.google.android.gms.maps.SupportMapFragment" 
      map:mapType="normal" 
      map:uiCompass="false" 
      map:uiRotateGestures="true" 
      map:uiScrollGestures="true" 
      map:uiTiltGestures="true" 
      map:uiZoomControls="false" 
      map:uiZoomGestures="true" /> 
</LinearLayout> 

그리고 조각에 asynchronically지도를로드

레이아웃 activity_main.xml은 다음과 같습니다. 나는 activity_main보기 팽창 할 때 :

LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
ViewGroup mainView = (ViewGroup) inflater.inflate(R.layout.activity_main, null); 

앱 충돌 및 반환 오류 :

내가 그것을 어떻게

01-15 19:25:16.045: E/AndroidRuntime(21115): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment 
을 를 해결할 수

?
mainView.setOnKeyListener(new OnKeyListener() 
    { 
     @Override 
     public boolean onKey(View v, int keyCode, KeyEvent event) 
     { 
      if(keyCode == KeyEvent.KEYCODE_POWER) 
      { 
       //STUFF 
      } 
     } 
    }); 

는 당신의 도움을 주셔서 감사합니다 : D 네임 스페이스를 선언해야

+0

휠을 재발견하려는 것 같습니다. 잘못된 길. 보기에 리스너를 추가해야합니까? 지도보기입니까? 커스텀 맵 조각을 만들고'onViewCreated (View, Bundle)'를 오버라이드한다. 매개 변수의 뷰는 맵 뷰입니다. 또한 자신이하는 일을 알지 못하는 이상 애플리케이션 컨텍스트에서 인플레이터를 사용하지 마십시오. –

+0

답변에 다른 코드를 게시했습니다. 내 문제가 지금 무엇인지 확인하십시오. – Skazza

+0

대신 다른 질문을 게시하는 것이 어떻습니까? –

답변

0

나는 (내가 조각없이 다른 응용 프로그램에서했던 것과 유사) 응용 프로그램에 전원 버튼의 모든 KeyListener를 설정하려면이 뷰 그룹이 필요합니다 첫 번째보기

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      xmlns:map="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/mapContainer" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      tools:context=".MainActivity" > 

<fragment 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:name="com.google.android.gms.maps.SupportMapFragment" 
     map:mapType="normal" 
     map:uiCompass="false" 
     map:uiRotateGestures="true" 
     map:uiScrollGestures="true" 
     map:uiTiltGestures="true" 
     map:uiZoomControls="false" 
     map:uiZoomGestures="true" /> 
</LinearLayout> 
+0

이것은 내 문제를 해결하지 못합니다. 응용 프로그램이 여전히 같은 오류와 충돌합니다. – Skazza

+0

죄송 합니다만 오류가 발생했습니다. 조각을 부 풀릴 수 없으며 조각이 조각 트랜잭션에 의해 처리됩니다. MyFragment fragment = (MyFragment) mainView.find .... –

+0

좋아, 그럼 어떻게 조각을 처리 할 수 ​​있습니까? 일부 키 리스너를 앱에 설정하려면? – Skazza

0

당신은 매니페스트 파일에이 줄을 추가 했 :

<meta-data 
      android:name="com.google.android.maps.v2.API_KEY" 
      android:value="YOUR_KEY" /> 

이 사이트를 한번 보시오 https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw

+0

아마도 내 문제를 이해하지 못합니다. 맵은 완벽하게 작동합니다. 앱에 대한 키 리스너를 추가하기 위해 액티비티에서 풍선 그룹을 가져와야합니다. – Skazza