1

I'm working with maps and I'm trying to do something similar as Uber does, show information near the marker (in two markers at the same time so I can't use infowindow )

enter image description here

As I have read I'm using IconFactory to achieve this:

    val iconFactory = IconGenerator(this)
    //iconFactory.setBackground(resources.getDrawable(R.drawable.background_iconfactory))
    iconFactory.setRotation(90)
    iconFactory.setContentRotation(-90)
    iconFactory.setContentView(view)


    val mMarkerA = mMap?.addMarker(MarkerOptions().position(LatLng(location.latitude, location.longitude)).anchor(iconFactory.anchorU, iconFactory.anchorV))
    mMarkerA?.setIcon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon("hello world")))

But I came up with the next problem: If I use a regular text the iconFactory is placed like I want. enter image description here

But if I inflate a custom view (this is what i need), the view appeared to be displaced to the right. enter image description here

Does anybody knows what I'm doing wrong?! Can anybody help me?

Thanks in advance.

Edit I don't think the xml could be a problem, if I don't rotate the content it's ok. enter image description here

Anyway I post the xml:

 <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<ImageView
    android:id="@+id/backgroundMarker"
    android:layout_width="30dp"
    android:layout_height="30dp"

    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/background_marker" />

<ImageView
    android:id="@+id/image_person"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="@+id/backgroundMarker"
    app:layout_constraintEnd_toEndOf="@+id/backgroundMarker"
    app:layout_constraintStart_toStartOf="@+id/backgroundMarker"
    app:layout_constraintTop_toTopOf="@+id/backgroundMarker"
    app:srcCompat="@drawable/ic_person_white_24dp" />

<ImageView
    android:id="@+id/imageView9"
    android:layout_width="1dp"
    android:layout_height="10dp"
    app:layout_constraintEnd_toEndOf="@+id/backgroundMarker"
    app:layout_constraintStart_toStartOf="@+id/backgroundMarker"
    app:layout_constraintTop_toBottomOf="@+id/backgroundMarker"
    app:srcCompat="@android:color/black" />

<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginStart="4dp"

    android:background="@android:color/white"
    android:padding="8dp"
    android:text="Calle Pepe dos aguas"
    app:layout_constraintBottom_toBottomOf="@+id/imageView9"
    app:layout_constraintStart_toEndOf="@+id/backgroundMarker"
    app:layout_constraintTop_toTopOf="@+id/backgroundMarker" />



  <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_marginEnd="8dp"
        android:background="@android:color/black"
        android:padding="4dp"
        android:tint="@android:color/white"
        app:layout_constraintBottom_toBottomOf="@+id/text"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toEndOf="@+id/text"
        app:layout_constraintTop_toTopOf="@+id/text"
        app:layout_constraintVertical_bias="0.0"
        app:srcCompat="@android:drawable/ic_secure" />
</android.support.constraint.ConstraintLayout>
4

0 回答 0