Расположение координат не работает с Linearlayout - PullRequest
0 голосов
/ 23 января 2019

Я хочу скрыть панель инструментов и держать вкладки при прокрутке списка вниз, но проблема в том, что когда я размещаю линейное расположение внутри макета координатора, панель инструментов не скрывается, когда я удаляю линейный макет, он работает, но дочерние представления меняют своиместа, которые я не хочу, я пытался переместить линейное расположение ниже appbarlayout, но баннер прокручивается при прокрутке вниз, вот основное действие xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/primary_color"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:context="com.example.ringtone.MainActivity"
    tools:openDrawer="start">


    <android.support.design.widget.CoordinatorLayout 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="match_parent"
        tools:context=".MainActivity">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            >
            <android.support.design.widget.AppBarLayout
                android:id="@+id/appBar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                >

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="@color/primary_color"
                    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                    app:layout_scrollFlags="scroll|enterAlways|snap"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

                    <Button
                        android:id="@+id/more_toolbar"
                        android:layout_width="30dp"
                        android:layout_height="30dp"
                        android:layout_gravity="end"
                        android:layout_marginEnd="8dp"
                        android:background="@drawable/thumbsuo" />
                </android.support.v7.widget.Toolbar>

                <android.support.design.widget.TabLayout
                    android:id="@+id/tabs"
                    style="@style/CategoryTab"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>


            </android.support.design.widget.AppBarLayout>

            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                />

            <ProgressBar
                android:id="@+id/progressBarParent"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="match_parent"
                android:layout_height="10dp"
                android:layout_marginBottom="2dp"   
                />

            <com.google.android.gms.ads.AdView
                xmlns:ads="http://schemas.android.com/apk/res-auto"
                android:id="@+id/adView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                ads:adSize="SMART_BANNER"
                ads:adUnitId="ca-app-pub-3940256099942544/6300978111">

            </com.google.android.gms.ads.AdView>
        </LinearLayout>


    </android.support.design.widget.CoordinatorLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/primary_color"
        app:headerLayout="@layout/nav_header"
        app:itemIconTint="@color/text_drawer_color"
        app:itemTextColor="@color/text_drawer_color"
        app:menu="@menu/drawer_menu" />
</android.support.v4.widget.DrawerLayout>

есть ли решение?Заранее спасибо ??

1 Ответ

0 голосов
/ 23 января 2019

для всех, кто все еще сталкивается с этой проблемой, вот решение, вам просто нужно поместить координатный макет внутри относительного макета и добавить android: layout_above = "@ id / progressBarParent" (или @ id / adView, если у вас нет pregrassbar ), вот полный файл xml Activity_main:

<android.support.v4.widget.DrawerLayout
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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/primary_color"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.example.ringtone.MainActivity"
tools:openDrawer="start">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.candyx.testapp.Activity">

<android.support.design.widget.CoordinatorLayout 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="match_parent"
    tools:context=".MainActivity"
    android:layout_above="@id/progressBarParent">


        <android.support.design.widget.AppBarLayout
            android:id="@+id/appBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            >

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/primary_color"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                app:layout_scrollFlags="scroll|enterAlways|snap"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

                <Button
                    android:id="@+id/more_toolbar"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_gravity="end"
                    android:layout_marginEnd="8dp"
                    android:background="@drawable/thumbsuo" />
            </android.support.v7.widget.Toolbar>

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                style="@style/CategoryTab"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>


        </android.support.design.widget.AppBarLayout>



        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            />







</android.support.design.widget.CoordinatorLayout>


<ProgressBar
    android:id="@+id/progressBarParent"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="10dp"
    android:layout_marginBottom="2dp"
    android:layout_above="@+id/adView"


    />

<com.google.android.gms.ads.AdView
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
    android:layout_gravity="center|bottom"
    android:layout_alignParentBottom="true">

</com.google.android.gms.ads.AdView>

</RelativeLayout>
<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="@color/primary_color"
    app:headerLayout="@layout/nav_header"
    app:itemIconTint="@color/text_drawer_color"
    app:itemTextColor="@color/text_drawer_color"
    app:menu="@menu/drawer_menu" />

...