在谷歌地图Android上设置对话位置
我想在单击的标记上方实现一个类似视图的信息窗口。信息窗口对我没有用处,因为我想在它里面实现多个按钮。我可以在点击标记时创建对话框,也可以设置它的重力,例如:Gravity.TOP 我从地图的投影中得到屏幕的像素位置。但无法设置对话框在地图上的位置 以下是我的onMarkerClick方法:在谷歌地图Android上设置对话位置,android,google-maps,dialog,position,map-projections,Android,Google Maps,Dialog,Position,Map Projections,我想在单击的标记上方实现一个类似视图的信息窗口。信息窗口对我没有用处,因为我想在它里面实现多个按钮。我可以在点击标记时创建对话框,也可以设置它的重力,例如:Gravity.TOP 我从地图的投影中得到屏幕的像素位置。但无法设置对话框在地图上的位置 以下是我的onMarkerClick方法: @Override public boolean onMarkerClick(Marker arg0) { Log.d(TAG, "Marker Clicked"+ arg0.get
@Override
public boolean onMarkerClick(Marker arg0) {
Log.d(TAG, "Marker Clicked"+ arg0.getTitle());
final Dialog d = new Dialog(this);
d.requestWindowFeature(Window.FEATURE_NO_TITLE);
d.getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE));
d.setContentView(R.layout.info_window_layout);
AppCompatImageView btnAction1 = d.findViewById(R.id.action1);
AppCompatImageView btnAction2 = d.findViewById(R.id.action2);
AppCompatImageView btnAction3 = d.findViewById(R.id.action3);
final LatLng latlong = arg0.getPosition();
Projection projection = mMap.getProjection();
// Returns a screen location that corresponds to a geographical coordinate
Point screenPosition = projection.toScreenLocation(latlong);
Window window = d.getWindow();
WindowManager.LayoutParams wlp = window.getAttributes();
wlp.x = screenPosition.x;
wlp.y = screenPosition.y;
wlp.gravity = Gravity.NO_GRAVITY;
wlp.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(wlp);
d.show();
return true;
}
我的信息窗口布局.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp">
<android.support.v7.widget.AppCompatImageView
android:id="@+id/action1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_action1"/>
<android.support.v7.widget.AppCompatImageView
android:id="@+id/action2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_action2"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/>
<android.support.v7.widget.AppCompatImageView
android:id="@+id/action3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_actione3"/>
</LinearLayout>