Не работает исправление ширины на карте Google в окне информации - PullRequest
0 голосов
/ 22 февраля 2020

android studio 3.6

  compileSdkVersion 29
  buildToolsVersion "29.0.3"

implementation 'com.google.android.gms:play-services-maps:17.0.0'

здесь мой макет

<?xml version="1.0" encoding="utf-8"?>
<layout 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">

    <data>

    </data>

    <LinearLayout
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/titleContainerLayout"
            android:layout_width="match_parent"
            android:layout_height="@dimen/min_height"
            android:layout_marginStart="@dimen/half_default_margin"
            android:layout_marginTop="@dimen/default_margin"
            android:layout_marginEnd="@dimen/half_default_margin"
            android:background="@drawable/bottom_border_bg"
            android:orientation="vertical">

            <TextView
                android:id="@+id/titleTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/half_default_margin"
                android:text="Gaz station"
                android:textColor="@android:color/black"
                android:textSize="15sp" />

            <TextView
                android:id="@+id/stateTtextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/half_default_margin"
                android:text="@string/open"
                android:textColor="@android:color/holo_green_light"
                android:textSize="14sp"
                app:layout_constraintBottom_toBottomOf="parent" />
        </LinearLayout>


        <LinearLayout
            android:id="@+id/agentInfoContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/bottom_border_bg"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/containerAddress"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/half_default_margin"
                android:layout_marginTop="@dimen/half_default_margin"
                android:layout_marginEnd="@dimen/half_default_margin">

                <TextView
                    android:id="@+id/addressLabelTextView"
                    style="@style/mapMarkerInfoItemLabelTextStyle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/half_default_margin"
                    android:layout_marginEnd="@dimen/half_default_margin"
                    android:text="@string/address_colon" />

                <TextView
                    android:id="@+id/addressValueTextView"
                    style="@style/mapMarkerInfoItemLabelTextStyle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="@dimen/half_default_margin"
                    android:gravity="end" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/containerWorkingHours"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/half_default_margin"
                android:layout_marginTop="@dimen/half_default_margin"
                android:layout_marginEnd="@dimen/half_default_margin">

                <TextView
                    android:id="@+id/workingHoursLabelTextView"
                    style="@style/mapMarkerInfoItemLabelTextStyle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/half_default_margin"
                    android:layout_marginEnd="@dimen/half_default_margin"
                    android:text="@string/working_hours_colon" />

                <TextView
                    android:id="@+id/workingHoursValueTextView"
                    style="@style/mapMarkerInfoItemLabelTextStyle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="@dimen/half_default_margin"
                    android:gravity="end"
                    app:layout_constraintEnd_toEndOf="parent" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/containerPhon"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/half_default_margin"
                android:layout_marginTop="@dimen/half_default_margin"
                android:layout_marginEnd="@dimen/half_default_margin"
                android:layout_marginBottom="@dimen/half_default_margin">

                <TextView
                    android:id="@+id/phoneLabelTextView"
                    style="@style/mapMarkerInfoItemLabelTextStyle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/half_default_margin"
                    android:layout_marginEnd="@dimen/half_default_margin"
                    android:text="@string/phone_colon" />

                <TextView
                    android:id="@+id/phoneValueTextView"
                    style="@style/mapMarkerInfoItemLabelTextStyle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="@dimen/half_default_margin"
                    android:gravity="end" />

            </LinearLayout>

        </LinearLayout>

        <LinearLayout
            android:id="@+id/containerServices"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/half_default_margin"
            android:layout_marginTop="@dimen/half_default_margin"
            android:layout_marginEnd="@dimen/half_default_margin"
            android:layout_marginBottom="@dimen/half_default_margin"
            android:orientation="vertical">

            <TextView
                android:id="@+id/servicesLabelTextView"
                style="@style/mapMarkerInfoItemLabelTextStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/half_default_margin"
                android:layout_marginEnd="@dimen/half_default_margin"
                android:text="@string/services_colon" />


            <GridLayout
                android:id="@+id/gridLayoutServiceContainer"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:columnCount="5"
                android:orientation="horizontal"
                android:useDefaultMargins="true">

            </GridLayout>



        </LinearLayout>

    </LinearLayout>

</layout>

стилей. xml

<style name="mapMarkerInfoItemLabelTextStyle">
        <item name="android:textSize">15sp</item>
        <item name="android:textColor">@android:color/black</item>
    </style>

здесь активность:

import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
import md.qsystems.android.tango.client.databinding.MapActivityBinding
import com.google.android.gms.maps.SupportMapFragment
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.model.BitmapDescriptorFactory
import com.google.android.gms.maps.model.MarkerOptions
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.Marker
class MapActivity : AppCompatActivity(), OnMapReadyCallback {

private lateinit var mMap: GoogleMap
mMap.setInfoWindowAdapter(object : GoogleMap.InfoWindowAdapter {
            override fun getInfoWindow(marker: Marker): View? {
                return null
            }

            // Important! Not work with "androidx.constraintlayout.widget.ConstraintLayout"
            override fun getInfoContents(marker: Marker): View? {
                val markerLatLng = marker.position
                val selectGazStation =
                    gazStationsList.first { it.latitude == markerLatLng.latitude && it.longitude == markerLatLng.longitude }
                Debug.d(TAG, "getInfoContents: selectGazStation = $selectGazStation")
                val mapMarkerInfoContentLayoutBinding =
                    MapMarkerInfoContentLayoutBinding.inflate(LayoutInflater.from(applicationContext));
                //mapMarkerInfoContentLayoutBinding.setVariable(BR.model, selectGazStation)
                mapMarkerInfoContentLayoutBinding.addressValueTextView.setText(selectGazStation.address)
                var workingHours = "24/24"
                if (!selectGazStation.workingHours?.contains("NON-STOP", true)!!) {
                    workingHours = selectGazStation.workingHours!!
                }
                mapMarkerInfoContentLayoutBinding.workingHoursValueTextView.setText(workingHours)
                mapMarkerInfoContentLayoutBinding.phoneValueTextView.setText(selectGazStation.phone)
                mapMarkerInfoContentLayoutBinding.gridLayoutServiceContainer.removeAllViews()
                return mapMarkerInfoContentLayoutBinding.root
            }
        })

и вот результат, когда я нажимаю на разные маркеры:

enter image description here

enter image description here

как вы можете видеть, как информационное окно меняет свою ширину? Почему? Я исправляю его ширину на 200 dp

android:layout_width="200dp"

почему это не работает?

1 Ответ

1 голос
/ 22 февраля 2020
<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/titleContainerLayout"
            android:layout_width="200dp"
            android:layout_height="@dimen/min_height"
            android:layout_marginStart="@dimen/half_default_margin"
            android:layout_marginTop="@dimen/default_margin"
            android:layout_marginEnd="@dimen/half_default_margin"
            android:background="@drawable/bottom_border_bg"
            android:orientation="vertical">

Я просто заменяю основную ширину LinearLayout на вторую.

...