我需要一些信息,因为我不知道这是否可行。
我有碎片活动,在那里我有标签。选项卡是列表片段。我的问题:
我需要列表中的一些自定义视图。我有一些信息,下面我有一张地图,上面有一个指向那个地方的别针。这有可能吗???ListFrragment中的MapFragment???
如果你能说这是可能的,并为我指明如何实施它的正确方向,我将不胜感激!!!
谢谢。。。
这有可能吗?
使用某种静态地图图像,当然。谷歌有一个静态地图API,虽然主要用于网络,但原则上你也可以从Android应用程序中获得它。
ListFrragment中的MapFragment?
将片段放入ListView
行将是困难的,甚至是不可能的,因为ListView
希望其子级是Views
,所以您可能需要使用MapView
而不是MapFragment
。此外,您还遇到了滚动地图的所有问题。而且,这是一个非常重量级的解决方案,所以我预计会出现性能问题。
我刚刚遇到了一个类似的问题,并提出了以下解决方案。顺便说一句,现在播放服务有谷歌地图精简模式。
假设您有一个使用BaseAdapter的ListView,那么您应该覆盖您的getView方法。这就是我的getView的样子:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if ( convertView == null )
convertView = new CustomItem(mContext,myLocations.get(position));
return convertView;
}
其中类CustomItem是表示我的行的FrameLayout。
public class CustomItem extends FrameLayout {
public int myGeneratedFrameLayoutId;
public CustomItem(Context context,Location location) {
super(context);
myGeneratedFrameLayoutId = 10101010 + location.id; // choose any way you want to generate your view id
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
FrameLayout view = (FrameLayout) inflater.inflate(R.layout.my_custom_item,null);
FrameLayout frame = new FrameLayout(context);
frame.setId(myGeneratedFrameLayoutId);
int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 150, getResources().getDisplayMetrics());
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT,height);
frame.setLayoutParams(layoutParams);
view.addView(frame);
GoogleMapOptions options = new GoogleMapOptions();
options.liteMode(true);
MapFragment mapFrag = MapFragment.newInstance(options);
//Create the the class that implements OnMapReadyCallback and set up your map
mapFrag.getMapAsync(new MyMapCallback(location.lat,location.lng));
FragmentManager fm = ((Activity) context).getFragmentManager();
fm.beginTransaction().add(frame.getId(),mapFrag).commit();
addView(view);
}
希望它能帮助到别人。