4
片段我怎樣才能從RecyclerView.ViewHolderAndroid的谷歌地圖在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,而不是地圖片段它的工作原理,但不刷新地圖。點擊地圖幾次後,地圖刷新。 問候,愛爾蘭人
從XML編碼你貼,你用cardview,所以做你mapfragment是不是裏面一個回收者視圖。另外你什麼意思不刷新?您可以在這裏查看recyclerview的文檔:https://developer.android.com/training/material/lists-cards.html – ztan
問題是如何獲取地圖片段。如果我在xml中有TextView(用於行的xml),我可以將它作爲findViewById(R.id.my_text)在RecyclerView.ViewHolder中獲取;然後我可以將值設置爲RowHolder.myText.setText(「test」);我如何使用地圖片段來做到這一點? –
不刷新,我的意思是它處於某種暫停模式。它顯示模糊的地圖,然後當我點擊時,它將地圖更新爲更好的圖像,然後再單擊它更新一些標籤,如果我點擊更多時間,則會更新地圖。 –