Android Google在RecyclerView.ViewHolder中映射片段

时间:2015-01-16 11:02:47

标签: android google-maps android-fragments android-adapter android-viewholder

如何从RecyclerView.ViewHolder

访问GoogleMap

我有:

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而不是map fragment它可以工作,但不会刷新地图。点击地图几次后,地图会刷新。 此致,Ales

0 个答案:

没有答案