Reputation: 3029
When I click a marker, appears a balloon. But there are too space between the marker and the balloon, so how I can reduce this distance?. It's like using the setBalloonBottomOffset
method in the V1 Google Map
.
My custom balloon
is this class:
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("");
}
}
}
I show a marker like
marker.showInfoWindow();
My balloon xml is
<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>
Upvotes: 6
Views: 3293
Reputation: 7671
This is an old question, the current API has a MarkerOptions.infoWindowAnchor method which may help.
Upvotes: 0
Reputation: 200030
Map Markers are 'anchored' by default to the middle of the bottom of your layout (i.e., anchor(0.5,1)).
You can change the anchor point by using MarkerOptions.anchor when you create your Marker.
Upvotes: 2
Reputation: 21086
Have you tried using negative bottom margin for your whole balloon layout? Like so:
<RelativeLayout
android:layout_width="250dp"
android:layout_height="75dp"
android:background="@drawable/ballon"
android:layout_marginBottom="-8dp" >
Probably won't work or cause content to be cut off at the bottom, but still worth trying as the simplest approach. Perhaps there's another way to trick GoogleMap
class but it's hard to figure out not having the source code to the API.
Another tip: you probably don't need your getInfoContents()
method – just return null
there. This method will only be called if you return null
from getInfoWindow()
(see here) – to incorporate your content view into default info window, which is clearly not your goal since you want to move balloon around.
Consequently, you can also throw out mContents
, it's totally redundant, just takes up mem for another copy of your inflated view hierarchy that never gets used.
Tell me if the margin thing works for you. We could probably also try to make use of something like ((View)mWindow.getParent())
later when the item is being displayed but that would be trickier so I sugget to just try the margin first.
Upvotes: 0