Что-то не так с xml Tabs - PullRequest
       2

Что-то не так с xml Tabs

1 голос
/ 05 февраля 2020

Это мои вкладки в приложении

Первая вкладка

Вторая вкладка

Что я делаю не так? Моя Activity_main. xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        app:srcCompat="@drawable/header_logo" />

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"></TabWidget>
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
            </FrameLayout>
        </LinearLayout>
    </TabHost>
</LinearLayout>

Моя первая деятельность xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:mapbox="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.mapbox.mapboxsdk.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        mapbox:mapbox_cameraTargetLat="59.908008"
        mapbox:mapbox_cameraTargetLng="30.319100"
        mapbox:mapbox_cameraZoom="8"/>

</FrameLayout>

И вторая деятельность

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        app:srcCompat="@drawable/mapbox_compass_icon" />

    <TextView
        android:id="@+id/idtest"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Информация"></TextView>
</LinearLayout>

Мне нужно дизайн выглядит следующим образом

Как я вижу это в Android Studio

Я не понимаю, в чем проблема, я создал все из урока в русский форум (я русскоговорящий)

Ответы [ 2 ]

1 голос
/ 05 февраля 2020

Ваш xml файл готов

далее Поместите этот код в MainActivity. java файл для добавления Tab в TabHost

//Assign id to Tabhost.
    TabHostWindow = (TabHost) findViewById(android.R.id.tabhost);

    //Creating tab menu.
    TabSpec TabMenu1 = TabHostWindow.newTabSpec("First tab");
    TabSpec TabMenu2 = TabHostWindow.newTabSpec("Second Tab");

    //Setting up tab 1 name.
    TabMenu1.setIndicator("Tab1");
    //Set tab 1 activity to tab 1 menu.
    TabMenu1.setContent(new Intent(this, TabActivity_1.class));

    //Setting up tab 2 name.
    TabMenu2.setIndicator("Tab2");
    //Set tab 3 activity to tab 1 menu.
    TabMenu2.setContent(new Intent(this, TabActivity_2.class));

    TabHostWindow.addTab(TabMenu1);
    TabHostWindow.addTab(TabMenu2);

для получения дополнительной информации посетите this

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

Вам просто нужно добавить отдельный файл макета, который включает вкладки и панель действий

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