我想在长按地图时制作一个弹出窗口,这是我的代码和 popup.xml:但是 popupwindow 没有出现,并且Log
告诉窗口正在显示。Constructor
此外, and函数有很多版本,showAtLocation
我不太清楚它们之间的区别。有人能在我的代码中找到错误吗?非常感谢!
private void init()
{
mGMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
if( mGMap != null )
{
mGMap.setMyLocationEnabled(true);
mGMap.getUiSettings().setMyLocationButtonEnabled(true);
mGMap.getUiSettings().setRotateGesturesEnabled(true);
mGMap.getUiSettings().setCompassEnabled(true);
mGMap. setOnMapLongClickListener (new GoogleMap.OnMapLongClickListener(){
@Override
public void onMapLongClick(LatLng point) {
// TODO Auto-generated method stub
View popup_view = getLayoutInflater().inflate(R.layout.popup, null);
PopupWindow popupWindow = new PopupWindow(popup_view);
View parent = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getView();
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
@SuppressWarnings("deprecation")
int xoff = windowManager.getDefaultDisplay().getWidth() / 2 - popupWindow.getWidth() / 2;
// 使其聚集
popupWindow.setFocusable(true);
// 设置允许在外点击消失
popupWindow.setOutsideTouchable(false);
popupWindow.showAtLocation(parent, Gravity.CENTER, xoff, 0);
if(popupWindow.isShowing()){
Log.i(mainActivity.toString(), "pop up is showing");
}
popupWindow.update();
}
});
}
以下是我的 popup.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/location_time_tag"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="@string/loc_date" />
<ListView
android:id="@+id/listview_diary"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentLeft="true"
android:smoothScrollbar="true"
android:layout_below="@id/location_time_tag">
</ListView>
<EditText
android:id="@+id/add_note"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/listview_diary"
android:layout_alignParentLeft="true"
/>
<Button
android:id="@+id/add_text_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/add_note"
android:layout_alignParentLeft="true"
android:text="写日记"/>
<Button
android:id="@+id/del_text_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/add_text_btn"
android:layout_alignParentRight="true"
android:text="删日记"/>
</RelativeLayout>