0

Google Map Carousel (호출기) 프로젝트에서 작업 중이며 복잡한 레이아웃 인 Google지도를 복잡한 레이아웃 인 에 표시해야하지만 호출기를 이동할 때마다 mapfragment가로드되지 않습니다. 뒤쪽으로 가면지도가 갑자기 나타납니다.FragmentStatePagerAdapter의 SupportMapFragment입니다. 이전 및 첫 번째지도 조각 만 볼 수 있습니다.

MainActivity 

import android.content.Context; 
import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentActivity; 
import android.support.v4.app.FragmentManager; 
import android.support.v4.app.FragmentStatePagerAdapter; 
import android.support.v4.view.PagerTabStrip; 
import android.support.v4.view.ViewPager; 
import android.util.AttributeSet; 
import android.view.*; 
import com.google.android.gms.maps.CameraUpdate; 
import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 

import java.util.ArrayList; 

public class MainActivity extends FragmentActivity { 
    static final LatLng HAMBURG = new LatLng(53.558, 9.927); 
    static final LatLng KIEL = new LatLng(53.551, 9.993); 
    private GoogleMap map; 
    private ArrayList<MarkerOptions> mMarkers; 

    /** 
    * Called when the activity is first created. 
    */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 


     ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager); 
     viewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager())); 


    } 


} 

class MyMapFragment extends SupportMapFragment { 
    @Override 
    public void onActivityCreated(Bundle savedInstanceState) { 
     super.onActivityCreated(savedInstanceState); 

     GoogleMap map = getMap(); 

     if (savedInstanceState == null) { 
      CameraUpdate center = 
        CameraUpdateFactory.newLatLng(new LatLng(40.76793169992044, 
          -73.98180484771729)); 
      CameraUpdate zoom = CameraUpdateFactory.zoomTo(15); 

      map.moveCamera(center); 
      map.animateCamera(zoom); 
     } 

     addMarker(map, 40.748963847316034, -73.96807193756104); 
     addMarker(map, 40.76866299974387, -73.98268461227417); 
     addMarker(map, 40.765136435316755, -73.97989511489868); 
     addMarker(map, 40.70686417491799, -74.01572942733765); 
     setRetainInstance(true); 
    } 

    private void addMarker(GoogleMap map, double lat, double lon) { 
     map.addMarker(new MarkerOptions().position(new LatLng(lat, lon))); 

    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     super.onCreateView(inflater, container, savedInstanceState); 
     View view = inflater.inflate(R.layout.ttt, null); 
     getActivity().getSupportFragmentManager() 
       .beginTransaction() 
       .add(R.id.map_layout, newInstance()) 
       .commit(); 
     return view; 
    } 
} 

class MyPagerAdapter extends FragmentStatePagerAdapter { 

    public MyPagerAdapter(FragmentManager fm) { 
     super(fm); 
    } 

    @Override 
    public Fragment getItem(int i) { 
     return new MyMapFragment(); //To change body of implemented methods use File | Settings | File Templates. 
    } 

    @Override 
    public int getCount() { 
     return 10; //To change body of implemented methods use File | Settings | File Templates. 
    } 

    @Override 
    public String getPageTitle(int position) { 
     return ("page " + String.valueOf(position + 1)); 
    } 
} 

class MapAwarePager extends ViewPager { 
    public MapAwarePager(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    @Override 
    protected boolean canScroll(View v, boolean checkV, int dx, int x, 
           int y) { 
     if (v instanceof SurfaceView || v instanceof TextureView || v instanceof PagerTabStrip) { 
      return (true); 
     } 

     return (super.canScroll(v, checkV, dx, x, y)); 
    } 
} 

및 main.xml에

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
     > 
    <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Hello World, MainActivity" 
      /> 
    <view android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      class="com.spot.maps.MapAwarePager" android:id="@+id/view_pager"/> 
</LinearLayout> 

및 ttt.xml 내가 조각을위한 장소가 :

<?xml version="1.0" encoding="utf-8"?> 

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

    <EditText 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="New EditText" 
      android:id="@+id/editText" android:layout_gravity="left|center_vertical" android:layout_weight="1"/> 
    <FrameLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" android:layout_gravity="left|center_vertical" android:layout_weight="1" 
      android:id="@+id/map_layout"> 
    </FrameLayout> 
    <Button 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="New Button" 
      android:id="@+id/button" android:layout_weight="1"/> 
</LinearLayout> 

그리고 내 Mainfest.xml

다음은 내 코드입니다
<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
      package="com.spot.maps" 
      android:versionCode="1" 
      android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="10"/> 
    <permission 
    android:name="com.spot.maps.permission.MAPS_RECEIVE" 
    android:protectionLevel="signature" /> 
    <uses-feature 
      android:glEsVersion="0x00020000" 
      android:required="true" /> 
    <uses-permission android:name="com.spot.maps.permission.MAPS_RECEIVE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <!--<uses-permission android:name="android.permission.INTERNET"/>--> 
    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:hardwareAccelerated="true"> 

     <activity android:name="MainActivity" 
        android:screenOrientation="portrait" 
        android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN"/> 
       <category android:name="android.intent.category.LAUNCHER"/> 
      </intent-filter> 
     </activity> 
     <meta-data 
       android:name="com.google.android.maps.v2.API_KEY" 
       android:value="AIzaSyChbP6k9pnX4kLoTnOfXHFJK5Y_nM1wSqQ" /> 
    </application> 
</manifest> 

더 나은 이해를 위해.

희망을 보내 주시면 감사하겠습니다.

답변

0

ViewPager 런타임은 손질이 어려우므로 unexpected results에 대한 여유 공간이 많습니다.

호출기 용 어댑터에 유의하십시오. 수많은 예제는 내부 클래스를 사용하여 구현합니다. 어댑터

주 2의 일반적인 유형 중 하나를 어댑터 뷰 ArrayList의 인스턴스를 결합 할 수 있다는 ViewPagers

참고 사용 완전히 다른 방법은 ViewPager 프레임 워크를로드하는 데 사용될 수있다. FragmentTransaction에서 호출을 반복하는 대신, adapter.notifyDataSetChanged()를 호출하기 전에 어댑터의 ArrayList 객체에 단편을 간단히 추가 할 수 있습니다. ViewPager는 자동으로 메모리를 관리하고 훨씬 더 큰 ArrayList 객체에서 가장 관련성이 높은 mapView를 메모리에 유지 관리해야합니다.

...

많은 샘플로 전화 한 후 "onNotifyDataSetChanged()"를 ArrayList에 객체를 통해 당신의 조각 어댑터를 넣고 :

last idea

짧은 답변의 예를 참조