1

Пишу приложение для android, вставил гугл карты, но ни как не могу понять, как делать перенос строки, ни \n \n\r \\n - ничего не помогает, на карте всё равно всё пишется в одну строчку. Как сделать перенос наподобие <br>?

mMap.addMarker(new MarkerOptions().position(new LatLng(59.961159, 30.291961)).title("Название точки").snippet("Станция метро \"Чкаловская\", Устройство расположено в вестибюле станции метро рядом со входом.\n" +
    "Часы работы\n" +
    "\n" +
    "Пн-Вс: 6:00 - 0:00")  );

Обновление

Спасибо, но он почему-то у вас ругается на xml файл, по идее же должно быть так?

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context="com.example.client6.tetrapolis.MapsActivity2"
android:name="com.google.android.gms.maps.SupportMapFragment"/>

И дальше ваш xml

Error:(9) Error parsing XML: junk after document element

1 ответ 1

2

Необходимо сделать кастомное информационное окно

    mMap.setInfoWindowAdapter(new Yourcustominfowindowadpater());

class Yourcustominfowindowadpater implements InfoWindowAdapter {
        private final View mymarkerview;

        Yourcustominfowindowadpater() {
            mymarkerview = getActivity().getLayoutInflater().inflate(
                R.layout.view_info_window, null);
    }

    public View getInfoWindow(Marker marker) {
        render(marker, mymarkerview);
        ((TextView) mymarkerview.findViewById(R.id.title)).setText(marker
                .getTitle());
        ((TextView) mymarkerview.findViewById(R.id.snippet)).setText(marker
                .getSnippet());
        return mymarkerview;
    }

    public View getInfoContents(Marker marker) {
        ((TextView) mymarkerview.findViewById(R.id.title)).setText(marker
                .getTitle());
        ((TextView) mymarkerview.findViewById(R.id.snippet)).setText(marker
                .getSnippet());
        return null;
    }

    private void render(Marker marker, View view) {
    }
}

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="@drawable/frame_white">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="12dp"
        android:maxLines="1"
        android:ellipsize="end"
        android:padding="5dp"
        android:textStyle="bold"/>
    <TextView
        android:id="@+id/snippet"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxLines="3"
        android:ellipsize="end"
        android:padding="5dp"
        android:textSize="10dp"/>
</LinearLayout>

</LinearLayout>
7
  • Спасибо, но он почему то у вас ругается на xml файл, по идее же должно быть так? <fragment xmlns:android="schemas.android.com/apk/res/android" xmlns:tools="schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/map" tools:context="com.example.client6.tetrapolis.MapsActivity2" android:name="com.google.android.gms.maps.SupportMapFragment"/> И дальше ваш xml Error:(9) Error parsing XML: junk after document element 21 окт 2014 в 10:32
  • Вы добавили в мой xml карту? Тот xml, который скинул я, описывает только информационное окно, всплывающее при клике на маркер. Сам фрагмент с картой должен быть в отдельном xml файле.
    – Lsoldier52
    21 окт 2014 в 11:05
  • Гм, а как их соединить? Это всё маркеры для карты. 21 окт 2014 в 11:20
  • Свой код оставьте как есть, в папке layout создайте файл view_info_window. В него скопируйте мою разметку.
    – Lsoldier52
    21 окт 2014 в 12:28
  • и код java и xml? 21 окт 2014 в 18:12

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими пользовательским соглашением, политикой конфиденциальности и политикой о куки

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.