如何自定义我的infowindow android应用程序边框?

时间:2014-10-14 10:42:11

标签: android android-layout infowindow

大家好,我必须在我的Marker infowindow上的每个GoogleMap上为我的Android应用程序添加自定义图像。但我不能做的是使图像适合左,右和下边框,因为我认为默认的Infowindow属性在内容上有默认的填充或边距。

是否可以使用Infowindow拟合图像?这是我的截图和我的代码:

屏幕enter image description here

XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal|left"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/image_nuvoletta"
        android:layout_width="90dp"
        android:layout_height="60dp"
        android:layout_marginRight="5dp"
        android:paddingLeft="0px"
        android:adjustViewBounds="true"
        android:src="@drawable/ic_launcher"/>
[...]

getInfoContents的Java片段

public View getInfoContents(Marker marker) {

/* Distanza a piedi e macchina sulla nuvoletta */
/***********************************************/
GPSTracker gpsTracker = new GPSTracker(MainActivity.this);

if (gpsTracker.canGetLocation())
{
    String stringLatitude = String.valueOf(gpsTracker.latitude);
    String stringLongitude = String.valueOf(gpsTracker.longitude);

    double currentLat = Double.parseDouble(stringLatitude);
    double currentLng = Double.parseDouble(stringLongitude);

    double destLat = marker.getPosition().latitude;
    double destLng = marker.getPosition().longitude;

    final float[] results = new float[3];
    Location.distanceBetween(currentLat, currentLng, destLat, destLng, results);

    float metri = results[0];
    float km = Math.round((double)metri/1000);

    int minuti_persona = (int)Math.round(metri/125);    //125 metri al minuto -> velocità media di 2,5 m/s
    int minuti_auto = (int)Math.round(km/0.7);          //700 metri al minuto -> velocità media di 42 km/h 


    /***********************************************/


    View v = getLayoutInflater().inflate(R.layout.custom_info_window, null);
    TextView tvTitle = (TextView) v.findViewById(R.id.title);
    TextView tvSnippet = (TextView) v.findViewById(R.id.snippet);
    tvSnippet.setTypeface(tvSnippet.getTypeface(), Typeface.ITALIC); //indirizzo in corsivo
    TextView tvPedonal_distance = (TextView) v.findViewById(R.id.pedonal_time);
    TextView tvCar_distance = (TextView) v.findViewById(R.id.car_time);
    tvTitle.setText(marker.getTitle());
    tvSnippet.setText(marker.getSnippet());

    if(minuti_persona <=0)          // Stampa tempo per coprire la distanza
    {
        tvCar_distance.setText("A piedi: meno di un minuto");
    }else
    {
        tvPedonal_distance.setText("A piedi: "+minuti_persona+ " minuti");
    }

    if(minuti_auto <= 0)
    {
        tvCar_distance.setText("In auto: meno di un minuto");                                   
    }else
    {
         tvCar_distance.setText("In auto: " +minuti_auto+ " minuti");
    }

    //Prova immagine custom
    /***********************************/
    ImageView image;
    String currentUrl="http://upload.wikimedia.org/wikipedia/commons/5/50/Casa_Natale_Benito_Mussolini_(1).jpg";
    image = (ImageView) v.findViewById(R.id.image_nuvoletta);

    Picasso.with(v.getContext())
        .load(currentUrl)
        .error(R.drawable.ic_launcher)  //in caso di errore fa vedere questa immagine (un triangolo penserei)
        .resize(150, 110)
        .into(image); 
    /***********************************/

    return v;
    }else
    {
        View v = getLayoutInflater().inflate(R.layout.custom_info_window, null);
        TextView tvTitle = (TextView) v.findViewById(R.id.title);
        TextView tvSnippet = (TextView) v.findViewById(R.id.snippet);
        tvTitle.setText(marker.getTitle());
        tvSnippet.setText(marker.getSnippet());
        return v;
    }

}

非常感谢

1 个答案:

答案 0 :(得分:0)

只需覆盖xml自定义布局的背景并覆盖 getInfoWindow(Marker marker),而不是覆盖 getInfoContents(Marker marker)