【问题标题】:how to display PopupWindow centered to clicked point on screen?如何在屏幕上以点击点为中心显示 PopupWindow?
【发布时间】:2013-03-30 12:32:53
【问题描述】:

我最近实现了一个 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>        

【问题讨论】:

    标签: android onclick popupwindow gravity


    【解决方案1】:

    问题是应用程序没有全屏显示,所以点击LatLng转换的屏幕点与实际屏幕点不对应,偏移量是Android上顶部面板的高度。当我将应用程序设为全屏时,它有所帮助。但是,我仍然不知道如何获得 Android 顶部面板的高度...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-29
      • 1970-01-01
      • 1970-01-01
      • 2015-06-14
      • 2021-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多