4

에 조각을 매핑합니다안드로이드 구글은 내가 가지고 RecyclerView.ViewHolder</p>에서 <p>를 GoogleMap으로 얻을 수있는 방법 RecyclerView.ViewHolder

public class MapRowHolder extends RecyclerView.ViewHolder 
{ 
public MapRowHolder(View view) { 
     super(view); 
} 
} 

XML :

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:android.support.v7.cardview="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android.support.v7.cardview:cardBackgroundColor="@color/blue" 
android.support.v7.cardview:cardCornerRadius="@dimen/card_corner" 
android.support.v7.cardview:cardElevation="@dimen/card_elevation"> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_gravity="right|center_vertical" 
    android:gravity="center_vertical|right" 
    android:layout_width="fill_parent"> 


    <fragment xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:tag="maps" 

     android:id="@+id/map_view_fragment" tools:context=".Map" 
     android:name="com.google.android.gms.maps.SupportMapFragment" 
     android:layout_centerInParent="true"/> 

</LinearLayout> 

어댑터 :

public class MapAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> 
{ 


public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { 
     RecyclerView.ViewHolder mh; 


     View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_row, viewGroup, false); 
     mh = (RecyclerView.ViewHolder)new PodatkiZaMapRowHolder(v); 

     return mh; 
    } 

public void onBindViewHolder(RecyclerView.ViewHolder RowHolder, int polozaj) { 

     MapRowHolder mapRowHolder = (MapRowHolder)RowHolder; 


    } 


} 

지도를 올바르게 표시합니다. 그리고 그것은 지구 전체에 축소되었습니다. 그리고 중심에 0,0 위치.

ViewHolder에서 어떻게 맵 조각을 얻을 수 있습니까? 카메라를 다른 위치로 이동하고 싶습니다. (GoogleMap 객체를 얻은 후에이 작업을 수행 할 수 있습니다.) GoogleMap 객체를 어디에서 어떻게 가져야합니까?

MapView 대신 맵 조각을 사용하면 작동하지만지도를 새로 고치지 않습니다. 지도를 몇 번 클릭하면지도가 새로 고침됩니다. 감사합니다, Ales

+0

당신이 게시 코드, 당신은 cardview를 사용하므로으로 MapFragment을 내부되지 않습니다 리사이클 러뷰. 또한 새로 고침하지 않음으로써 무엇을 의미합니까? https://developer.android.com/training/material/lists-cards.html – ztan

+0

지도를 가져 오는 방법에 문제가 있습니다. TextView가 xml (행 xml)에 있으면 RecyclerView.ViewHolder에서 findViewById (R.id.my_text)로 가져올 수 있습니다. 그런 다음 RowHolder.myText.setText ("test")로 값을 설정할 수 있습니다. 지도 조각으로 이것을 어떻게 할 수 있습니까? –

+1

새로 고침을하지 않으면 일종의 일시 중지 모드입니다. 그것은 blured지도를 보여줍니다, 그러면 클릭하면 더 나은 이미지로지도가 업데이트되고, 다른 클릭 후 일부 라벨이 업데이트되고 더 많은 시간을 클릭하면 계속 업데이트됩니다. –

답변

4

내가 끝난 것은 동적으로 항목 레이아웃 내의 FrameLayout에 SupportMapFragment를 추가하는 것입니다. 유일한 ID를 가진 추가 FrameLayout을 만들어야합니다.

XML :

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

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="10dp"> 

    <TextView 
     android:id="@+id/car_name" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Peugeot 407 2.0 HDI" 
     android:textSize="20dp" 
     android:gravity="center_horizontal" 
     android:textColor="?attr/colorPrimary" 
     android:textStyle="bold" 
     android:layout_marginBottom="5dp" 
     /> 

    <include layout="@layout/ride_item_summary" /> 

    <FrameLayout 
     android:id="@+id/map_layout" 
     android:layout_marginTop="10dp" 
     android:layout_width="match_parent" 
     android:layout_height="170dp" 
     android:layout_marginBottom="10dp" 
     /> 
</LinearLayout> 

어댑터 :

는 XML에서
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 
    super.onBindViewHolder(holder, position); 
    switch (getItemViewType(position)) { 
      case 1: 
      if (first) { 
       ... //check if polyline is not null, init other views 

        FrameLayout view = (FrameLayout) ((RideItemHolder) holder).mMapLayout; 
        FrameLayout frame = new FrameLayout(mContext); 
        frame.setId(1010101); //you have to set unique id 

        int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 170, mContext.getResources().getDisplayMetrics()); 
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, height); 
        frame.setLayoutParams(layoutParams); 

        view.addView(frame); 

        GoogleMapOptions options = new GoogleMapOptions(); 
        options.liteMode(true); 
        SupportMapFragment mapFrag = SupportMapFragment.newInstance(options); 

        //Create the the class that implements OnMapReadyCallback and set up your map 
        mapFrag.getMapAsync(new MapReadyCallback()); 

        FragmentManager fm = fragment.getChildFragmentManager(); 
        fm.beginTransaction().add(frame.getId(), mapFrag).commit(); 

        first = false; 
       } 
      } 
      break; 
     case 2: 
      ... 

private class MapReadyCallback implements OnMapReadyCallback { 
    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     drawMap(googleMap); 
    } 
} 
관련 문제