Đây là cách bố trí tùy chỉnh của tôi cho cửa sổ thông tin của tôi:Làm thế nào để đặt drawable làm nền trên InfoWindow (API Google Maps v2 dành cho Android)?
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_infowindow" >
<LinearLayout
android:id="@+id/text_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
style="@style/TexTitle"
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
style="@style/TextDistance"
android:id="@+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
Và đây là bộ chuyển đổi tùy chỉnh của tôi:
public class MapInfoWindowAdapter implements InfoWindowAdapter{
private LayoutInflater inflater;
private Context context;
public MapInfoWindowAdapter(Context context){
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.context = context;
}
@Override
public View getInfoContents(Marker marker) {
// Getting view from the layout file
View v = inflater.inflate(R.layout.map_popup, null);
TextView title = (TextView) v.findViewById(R.id.title);
title.setText(marker.getTitle());
TextView address = (TextView) v.findViewById(R.id.distance);
address.setText(marker.getSnippet());
return v;
}
@Override
public View getInfoWindow(Marker arg0) {
// TODO Auto-generated method stub
return null;
}
}
Và đây là kết quả:
Tuy nhiên Tôi muốn tùy chỉnh drawable làm nền duy nhất cho cửa sổ thông tin của tôi, Làm thế nào để đạt được điều này?
Tôi thực sự đánh giá cao câu trả lời rõ ràng của bạn, tuy nhiên tôi đã nhận được NullPointerException sử dụng RelativeLayout làm gốc trong bố cục tùy chỉnh của tôi để tôi sử dụng LinearLayout thay thế. – IsaacCisneros
@IsaacCisneros Điều đó có lẽ sẽ là câu hỏi ban đầu của bạn sau đó. Đây là một vấn đề được biết đến. Xem phần này: [gmaps-api-issues] (https://code.google.com/p/gmaps-api-issues/issues/detail?id=4748). –
@ MaciejGórski mã thực sự tốt đẹp .... –