簡體   English   中英

協調器布局不適用於Linearlayout

[英]Coordinator layout is not working with Linearlayout

我想在向下滾動列表視圖時隱藏工具欄並保留選項卡,但是問題是當我將線性布局放置在協調器布局內時,工具欄沒有隱藏,當我刪除線性布局時它起作用了,但是子視圖改變了它們的位置不想,我試圖將linearlayout移到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>

有什么解決辦法嗎? 先感謝您 ??

對於仍然面臨此問題的每個人,這是解決方案y,您只需要將coordinatorlayout放置在相對布局內並添加android:layout_above =“ @ id / progressBarParent”(如果您沒有pregrassbar,則添加@ id / adView),在這里是完整的activity_main xml文件:

<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" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM