Как исправить supportFragmentManager? - PullRequest
0 голосов
/ 18 февраля 2020

Я пытаюсь поместить карты Google в SupportMapFragment моего MainActivity файла следующим образом:

val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as? SupportMapFragment
        mapFragment?.getMapAsync(this)

и

val mapFragment = supportFragmentManager
            .findFragmentById(R.id.map) as SupportMapFragment
        mapFragment.getMapAsync(this)

И модифицирую мой content_main.xml следующим образом:

 <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal"
                android:gravity="center_vertical">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/app_name"
                    android:textColor="#FFFFFF"
                    style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"/>
            </LinearLayout>

и

<LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="13"
                android:orientation="horizontal"
                android:gravity="center_vertical">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/app_name"
                    android:textColor="#FFFFFF"
                    style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"/>
            </LinearLayout>

но приложение работает следующим образом: Instead map should be displayed in white area

Любой совет?

РЕДАКТИРОВАТЬ Это мои Activity_Main.xml:

<include
        xmlns:tools="http://schemas.android.com/tools"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        layout="@layout/content_main"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

<!--<fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />-->

пс. Я удалил тег <fragment> для отладки некоторых частей.

1 Ответ

0 голосов
/ 19 февраля 2020

Я решил это; как парни смеются в комментариях, я буду публиковать для будущих ссылок, если у кого-то будет такая же ситуация:

val mapFragment = SupportMapFragment.newInstance()
        supportFragmentManager.beginTransaction().add(R.id.map, mapFragment)
            .commit()
        mapFragment.getMapAsync(this)

Спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...