【发布时间】:2013-02-14 15:45:26
【问题描述】:
当我点击一个标记时,会出现一个气球。但是标记和气球之间的空间太大,那么我怎样才能减少这个距离呢?这就像在V1 Google Map 中使用setBalloonBottomOffset 方法。
我的custom balloon是这个班级:
public class CustomInfoWindowAdapter implements InfoWindowAdapter {
private final View mWindow;
private final View mContents;
public CustomInfoWindowAdapter(Activity activity) {
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mWindow = inflater.inflate(R.layout.ballon, null);
mContents = inflater.inflate(R.layout.ballon, null);
}
@Override
public View getInfoWindow(Marker marker) {
render(marker, mWindow);
return mWindow;
}
@Override
public View getInfoContents(Marker marker) {
render(marker, mContents);
return mContents;
}
private void render(Marker marker, View view) {
String title = marker.getTitle();
TextView titleUi = ((TextView) view.findViewById(R.id.txtTitle));
if (title != null) {
titleUi.setText(title);
} else {
titleUi.setText("");
}
String snippet = marker.getSnippet();
TextView snippetUi = ((TextView) view.findViewById(R.id.txtPlace));
if (snippet != null) {
snippetUi.setText(snippet);
} else {
snippetUi.setText("");
}
}
}
我显示一个像
这样的标记marker.showInfoWindow();
我的气球 xml 是
<RelativeLayout
android:layout_width="250dp"
android:layout_height="75dp"
android:background="@drawable/ballon" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<TextView
android:id="@+id/txtTitle"
style="@style/Ballon_Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:paddingLeft="15dp"
android:paddingRight="50dp"
android:paddingTop="10dp"
android:singleLine="true"
android:text="Con mis amigos amigos" />
<TextView
android:id="@+id/txtPlace"
style="@style/Ballon_Place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:paddingBottom="20dp"
android:paddingLeft="15dp"
android:paddingRight="50dp"
android:singleLine="true"
android:text="Puerta del sol" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</RelativeLayout>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingRight="12dp"
android:paddingTop="18dp"
android:src="@drawable/icon_arrow" />
</RelativeLayout>
【问题讨论】:
-
您可以添加屏幕截图以便我们看到错误吗?我建议你 1-
return null;在getInfoContents内 2-在getInfoWindow内膨胀视图。不要重复使用。 -
它没有任何错误。主要问题是标记和气球之间的距离,当我有很多 poi 时,用户不知道点击了哪个 poi。所以,如果很难修复它,最好离开它。