Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 嵌套协调器&x2B;AppBar布局';它不工作了_Android - Fatal编程技术网

Android 嵌套协调器&x2B;AppBar布局';它不工作了

Android 嵌套协调器&x2B;AppBar布局';它不工作了,android,Android,我刚开始使用CoordinatorLayout和AppBar。我有一个布局活动\u home.xml <RelativeLayout 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

我刚开始使用
CoordinatorLayout
和AppBar。我有一个布局活动\u home.xml

<RelativeLayout 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.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <android.support.design.widget.CoordinatorLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <android.support.design.widget.AppBarLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <android.support.v7.widget.Toolbar
                        android:id="@+id/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="?attr/colorPrimary"
                        app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"
                        app:layout_scrollFlags="scroll|enterAlways">

                        <AutoCompleteTextView
                            android:id="@+id/ac_search"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:background="@android:color/transparent"
                            android:focusable="true"
                            android:hint="@string/search"
                            android:imeOptions="actionSearch"
                            android:singleLine="true"
                            android:visibility="gone"/>

                    </android.support.v7.widget.Toolbar>

                    <LinearLayout
                        android:id="@+id/layout_search_results"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:visibility="gone"
                        android:orientation="vertical">
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_margin="0dp"
                            android:background="@color/white"
                            android:orientation="horizontal"
                            android:paddingStart="@dimen/_6sdp"
                            android:paddingEnd="@dimen/_6sdp">

                            <CheckBox
                                android:id="@+id/cb_search_deals"
                                android:layout_width="wrap_content"
                                android:layout_height="50dp"
                                android:layout_gravity="bottom"
                                android:layout_marginStart="@dimen/_6sdp"
                                android:layout_weight="0.45"
                                android:button="@drawable/checkbox_button"
                                android:checked="true"
                                android:paddingStart="@dimen/_8sdp"
                                android:text="@string/Search_for_Deals"
                                android:textSize="13sp"/>

                            <View
                                android:layout_width="0.25dp"
                                android:layout_height="match_parent"
                                android:layout_weight="0.015"
                                android:background="@color/grey"/>

                            <CheckBox
                                android:id="@+id/cb_search_business"
                                android:layout_width="wrap_content"
                                android:layout_height="50dp"
                                android:layout_marginStart="@dimen/_12sdp"
                                android:layout_weight="0.50"
                                android:button="@drawable/checkbox_button"
                                android:paddingStart="@dimen/_8sdp"
                                android:text="@string/Search_for_Business"
                                android:textSize="13sp"/>
                        </LinearLayout>

                        <RelativeLayout
                            android:id="@+id/rl_search_results"
                            android:layout_width="match_parent"
                            android:layout_height="50dp"
                            android:layout_gravity="start|center_vertical"
                            android:background="@color/red"
                            android:gravity="start|center_vertical">

                            <TextView
                                android:id="@+id/tv_search_results"
                                android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
                                android:layout_alignParentStart="true"
                                android:layout_toStartOf="@+id/iv_filter_results"
                                android:paddingStart="15dp"
                                android:text="Showing 10 Results"
                                android:textAllCaps="false"
                                android:textColor="@color/white"
                                android:textSize="14sp"
                                android:textStyle="normal"/>

                            <ImageView
                                android:id="@+id/iv_filter_results"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_alignParentEnd="true"
                                android:layout_marginEnd="10dp"
                                android:src="@drawable/ic_filter"/>
                        </RelativeLayout>

                        <ListView
                            android:id="@+id/lv_search_results"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_margin="0dp"
                            android:divider="@color/white"
                            android:dividerHeight="0dp"
                            android:scrollbars="none"
                            android:visibility="visible"/>
                    </LinearLayout>

                    <FrameLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                        <android.support.design.widget.TabLayout
                            android:id="@+id/tab_layout"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:paddingStart="@dimen/_12sdp"
                            android:paddingEnd="@dimen/_12sdp"
                            android:scrollbars="none"
                            android:background="@color/red"
                            app:tabTextColor="@color/tab_text_color"
                            app:tabIndicatorColor="@color/white"
                            app:tabMode="scrollable"
                            app:tabSelectedTextColor="@color/white"
                            app:tabTextAppearance="@android:style/TextAppearance.DeviceDefault.Small" />

                        <ImageView
                            android:layout_width="match_parent"
                            android:layout_height="48dp"
                            android:src="@drawable/tabs_overlay" />

                    </FrameLayout>

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

                <FrameLayout
                    android:id="@+id/fragment_container"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:visibility="gone"/>

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

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

        </LinearLayout>

        <include layout="@layout/layout_navigation"/>

        <include layout="@layout/layout_filter"/>

    </android.support.v4.widget.DrawerLayout>

</RelativeLayout>

问题是当前布局的
activity\u home
协调器布局+应用程序栏效果不起作用,而
CoordinatorLayout
和应用程序栏工作正常。此实现在4.2.2上也不起作用。

正如您所注意到的,
ListView
仅支持从棒棒糖开始的嵌套滚动(这是对
AppBarLayout
滚动支持的要求)。在此之前,必须使用实现或的视图。

。是的,我知道
ListView
支持从
Lollipop
嵌套滚动。但是,如果您看到我的
活动_home
它有一个
AppBarLayout
围绕
工具栏和选项卡
fragment\u top\u deals
还有一个
AppBarLayout
环绕图像视图和布局。当我在TopDealsFragment选项卡上时,
AppBarLayout
的片段级别效果正在工作,
ImageView
在向上滚动时离开屏幕,但是
工具栏和选项卡在向上滚动时不会移出屏幕,这是
活动的一部分。请注意,activity_home的viewpager正在承载选项卡的所有片段。此外,我尝试将我的
列表视图
放入
嵌套滚动视图
中,但有问题吗?
NestedScrollView
就是这样使用的,否则我可能会误解!我的观点是,无论您是否将滚动事件包装在NestedScrollView中,您都无法从棒棒糖前的列表视图中获取滚动事件来使用AppBarLayout等。最好切换到RecyclerView,它在我说的棒棒糖的任何地方都更有效!
<RelativeLayout 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:background="@color/white"
    android:orientation="vertical">


    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white">


        <android.support.design.widget.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent">

    <ImageView
        android:id="@+id/banner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitXY" />

            <include
                layout="@layout/layout_filter_header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/banner" />

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

    <com.app.views.MultiSwipeRefreshLayout
        android:id="@+id/swipeRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="@dimen/_8sdp"
        android:layout_below="@+id/header"
        >

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clickable="true"
            >

            <ListView
                android:id="@+id/list_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbars="none"
                android:divider="@null"
                android:dividerHeight="@dimen/_8sdp"
              app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

            <TextView
                android:id="@+id/empty_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center_horizontal"
                android:text="@string/error_no_data"
                android:textSize="24sp"
                android:visibility="gone"/>

        </FrameLayout>

    </com.app.views.MultiSwipeRefreshLayout>

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



    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:visibility="gone"
        android:indeterminateDrawable="@drawable/custom_progress"
        style="?android:attr/progressBarStyle"/>

</RelativeLayout>