我最近实现了一个 PopupWindow,它恰好显示在我单击 GoogleMapv2 的位置。我将 LatLng 地图位置转换为屏幕位置,将重力设置为中心并显示在屏幕上。然后,在没有任何代码更改的情况下,它开始显示在点击点上方一点,我不知道出了什么问题。请帮忙!我渴望任何解决我的问题的方法,我实际上只是想在地图上的点击点上显示一个进度对话框。
这是我的代码:
mMap.setOnMapClickListener(new OnMapClickListener()
{
@Override
public void onMapClick(LatLng point)
{
View popUpView = getLayoutInflater().inflate(R.layout.popup, null);
LinearLayout layout = (LinearLayout) popUpView.findViewById(R.id.popup);
ProgressBar progressBar = new ProgressBar(MainActivity.this);
progressBar.setIndeterminateDrawable(getResources().getDrawable(R.drawable.dialog));
layout.addView(progressBar);
mpopup = new PopupWindow(popUpView, 30,30, false); //Creation of popup
mpopup.setOnDismissListener(MainActivity.this);
mpopup.setAnimationStyle(android.R.style.Animation_Dialog);
pinToScreen(point, popUpView);
}
});
}
}
private void pinToScreen(LatLng point, View popupView)
{
Projection projection = mMap.getProjection();
Point pixPoint = projection.toScreenLocation(point);
LatLng latlng=projection.fromScreenLocation(pixPoint);
DisplayMetrics dm = getResources().getDisplayMetrics();
int screenwidth = dm.widthPixels;
int screenheight = dm.heightPixels;
mpopup.showAtLocation(popupView, Gravity.CENTER,
pixPoint.x-screenwidth/2, pixPoint.y-screenheight/2;
}
R.layout.popup:
LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popup"
android:layout_width="fill_parent"
android:orientation="vertical"
android:background="@android:color/transparent"
android:layout_height="fill_parent"
android:gravity="center"
android:layout_gravity="center">
LinearLayout>
ProgressDialog 可绘制:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:visible="true"
android:innerRadius="60dp"
><solid
android:color="@color/skypicker_blue1"
/>
<stroke android:color="@color/transparent_blue2"
android:width="1dp"/>
</shape>