gpt4 book ai didi

android - 在 Google Maps api v2 中设置自定义 InfoWindow 的宽度

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:51:20 27 4
gpt4 key购买 nike

我在 map 上创建了标记。当我点击它们时,自定义信息窗口总是和屏幕一样宽。

我尝试设置 layout_width="200dp" 但这没有帮助。我也试过设置

view.setLayoutParams(new LayoutParams(GetDipsFromPixel(200), GetDipsFromPixel(300)));

我可以通过设置 snippetUi.setWidth(GetDipsFromPixel(200)); 来设置 TextView 的宽度,但布局仍然保持屏幕宽度。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#FFFFFF"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:padding="10dp" >

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#FFFFFF"
android:gravity="center_vertical">

<ImageView
android:id="@+id/worldmap_infowindow_profileimg"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/noimage" />

<TextView
android:id="@+id/worldmap_infowindow_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To do No.2."
android:textColor="#000000"
android:textSize="16sp"
android:textStyle="bold"
android:paddingLeft="5dp"/>
</LinearLayout>

<View android:id="@+id/separator"
android:background="#ababab"
android:layout_width = "fill_parent"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
android:layout_height="1dp"/>

<TextView
android:id="@+id/worldmap_infowindow_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="See the Giza Pyramids"
android:textColor="#000000"
android:textSize="16sp"
android:textStyle="bold" />

<TextView
android:id="@+id/worldmap_infowindow_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="It was fascinating! It's a shame that it was raining, though."
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="normal" />

</LinearLayout>

类:

 private class CustomInfoWindowAdapter implements InfoWindowAdapter {

private View view;

public CustomInfoWindowAdapter() {
view = getLayoutInflater().inflate(R.layout.custom_infowindow, null);
}

@Override
public View getInfoContents(Marker marker) {

if (WorldMap.this.myMarker != null
&& WorldMap.this.myMarker.isInfoWindowShown()) {
WorldMap.this.myMarker.hideInfoWindow();
WorldMap.this.myMarker.showInfoWindow();
}
return null;
}

@Override
public View getInfoWindow(final Marker marker) {
WorldMap.this.myMarker = marker;


final String title = marker.getTitle();
final TextView titleUi = ((TextView) view.findViewById(R.id.worldmap_infowindow_name));
if (title != null) {
titleUi.setText(title);
} else {
titleUi.setText("");
}

final String snippet = marker.getSnippet();
final TextView snippetUi = ((TextView) view.findViewById(R.id.worldmap_infowindow_details));
if (snippet != null) {
snippetUi.setText(snippet);
} else {
snippetUi.setText("");
}

return view;
}
}

enter image description here

最佳答案

基本上你只需要在根下面有另一个层次的布局,像这样:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:background="@android:color/transparent"
android:layout_height="wrap_content">

<LinearLayout
android:layout_width="250dp"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="horizontal">
...

关于android - 在 Google Maps api v2 中设置自定义 InfoWindow 的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23063902/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com