android在列表中显示MapView

时间:2017-02-21 13:42:48

标签: android google-maps android-mapview

我尝试使用baseAdaptor在listView中为每个项目加载mapView一切似乎都很好但是地图(mapviews)正在以这种方式加载(下面的图片是列表中的单个项目): enter image description here

适配器类:

public class InfoAdapter extends BaseAdapter {

protected MapView mMapView;
GoogleMap googleMap;
Activity activity;
Bundle bundle;
Context context;
LayoutInflater layoutInflater;
ArrayList<Info> infos;

public TripsAdapter(Activity activity, Context context, ArrayList<Info> infos, Bundle bundle) {
    this.context = context;
    this.activity = activity;
    this.layoutInflater = LayoutInflater.from(activity);
    this.infos = infos;
    this.bundle = bundle;
}

@Override
public int getCount() {
    return infos.size();
}

@Override
public Object getItem(int i) {
    return infos.get(i);
}

@Override
public long getItemId(int i) {
    return i;
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {

    if (view == null) {

        view = layoutInflater.inflate(R.layout.list_infos_item, viewGroup, false);

        view.findViewById(R.id.btnShare).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               //share it
            }
        });

    }
    mMapView = (MapView) view.findViewById(R.id.fragment_embedded_map_view_mapview);
    mMapView.onCreate(bundle);

    return view;

}
}

list_infos_item.xml是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    xmlns:map="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:padding="13dip">
    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_margin="3dip"
        android:padding="8.5dip"
        android:elevation="5dp"
        card_view:cardCornerRadius="4dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="5"
            android:orientation="vertical">

            <com.google.android.gms.maps.MapView
                android:id="@+id/fragment_embedded_map_view_mapview"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="3"/>

            <LinearLayout
                android:visibility="gone"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="2">

            </LinearLayout>


            <Button
                android:id="@+id/btnShare"
                style="@style/Widget.AppCompat.Button.Borderless.Colored"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="2"
                android:layout_marginTop="12dip"
                android:background="@color/yellow"
                android:text="Share it!"
                android:textAlignment="center"
                android:textColor="@color/black"
                android:textSize="@dimen/default_text_size" />

        </LinearLayout>

    </android.support.v7.widget.CardView>
</LinearLayout>

发生了什么?我该如何解决问题?

0 个答案:

没有答案