2
我最近實現了一個PopupWindow,它完全顯示在我點擊我的GoogleMapv2的位置上。 我將LatLng地圖位置轉換爲screenlocation,將重力設置爲居中並顯示在屏幕上。然後,沒有任何代碼的變化,它開始顯示在點擊點上方,我不知道什麼是錯的。請幫忙!我渴望任何解決方案,我的問題,我只是想顯示一個進度對話框到地圖上點擊的點。如何顯示PopupWindow居中點擊屏幕上的點?
這裏是我的代碼:
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>