アプリに Google マップを埋め込みたい。
しかし、アプリはズームボタンを表示するだけで、地図を見ることができませんでした。他のアプリケーションに切り替えて元に戻すと。マップショー!
そして、私のアプリの問題が何であるかを知りたいですか? それを修正する方法は?
これが私がすることです:
public final static int HANDLER_SHOW_GOOGLEMAP = 4;
public final static int HANDLER_HIDE_GOOGLEMAP = 5;
private final int ENUM_GOOGLE_FRAGMENT_ADD = 0;
private final int ENUM_GOOGLE_FRAGMENT_SHOW = 1;
private final int ENUM_GOOGLE_FRAGMENT_HIDE = 2;
private WeakReference<MyActivity> mActivity;
private LinearLayout m_mapLayout;
private MapFragment m_mapFragment;
public MyHandler(MyActivity activity) {
super(activity);
this.mActivity = new WeakReference<MyActivity>(activity);
// TODO Auto-generated constructor stub
}
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch (msg.what) {
case HANDLER_SHOW_GOOGLEMAP:
showGoogleMap();
break;
case HANDLER_HIDE_GOOGLEMAP:
hideGoogleMap();
break;
}
}
private void showGoogleMap() {
initGoogleMap();
m_mapLayout.setVisibility(View.VISIBLE);
googleMapFragmentTransaction(ENUM_GOOGLE_FRAGMENT_SHOW);
MyActivity theActivity = this.mActivity.get();
FrameLayout viewGroup = (FrameLayout) theActivity.getWindow()
.getDecorView();
if (null == viewGroup.findViewById(m_mapLayout.getId())) {
viewGroup.addView(m_mapLayout);
}
}
private void hideGoogleMap() {
initGoogleMap();
m_mapLayout.setVisibility(View.INVISIBLE);
googleMapFragmentTransaction(ENUM_GOOGLE_FRAGMENT_HIDE);
MyActivity theActivity = this.mActivity.get();
FrameLayout viewGroup = (FrameLayout) theActivity.getWindow()
.getDecorView();
if (null != viewGroup.findViewById(m_mapLayout.getId())) {
viewGroup.removeView(m_mapLayout);
}
}
private void initGoogleMap() {
if (null != m_mapLayout) {
return;
}
m_mapFragment = MapFragment.newInstance();
MyActivity theActivity = this.mActivity.get();
m_mapLayout = new LinearLayout(theActivity);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, 480);
m_mapLayout.setLayoutParams(lp);
m_mapLayout.setId(100011);
m_mapLayout.setY(200);
googleMapFragmentTransaction(ENUM_GOOGLE_FRAGMENT_ADD);
}
private void googleMapFragmentTransaction(int enumTransaction) {
MyActivity theActivity = this.mActivity.get();
FragmentManager fragmentManager = theActivity.getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
switch (enumTransaction) {
case ENUM_GOOGLE_FRAGMENT_ADD:
fragmentTransaction.add(m_mapLayout.getId(), m_mapFragment);
break;
case ENUM_GOOGLE_FRAGMENT_SHOW:
fragmentTransaction.show(m_mapFragment);
break;
case ENUM_GOOGLE_FRAGMENT_HIDE:
fragmentTransaction.hide(m_mapFragment);
break;
default:
break;
}
fragmentTransaction.commit();
}
私は写真をアップロードするのに十分な評判がありません。これは写真のリンクです: http://imgdata.hoop8.com/1309/336989570575.png