首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >嵌套Coordinator+AppBar布局不起作用

嵌套Coordinator+AppBar布局不起作用
EN

Stack Overflow用户
提问于 2015-08-11 11:46:01
回答 1查看 1.1K关注 0票数 2

我刚开始与CoordinatorLayout和AppBar合作。我有一个布局activity_home.xml

代码语言:javascript
复制
<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>

ViewPagerid=home_viewpager是处理表布局片段的方法。

它只在Lollipop上工作很好,因为我在代码中设置了listview.setNestedScrollEnabed(true),但它在4.2.2上不起作用,而且视图的第一个片段(带有标题的列表视图)正在从底部被切断,即没有显示完整的屏幕内容。

在我的第二个具有布局名称fragment_top_deals的查看器片段中

代码语言:javascript
复制
<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>

问题是,activity_home协调器布局+ Appbar效果不起作用,相反,当前布局的CoordinatorLayout和Appbar运行良好。这一实现也不适用于4.2.2。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-11 16:18:30

正如您注意到的,ListView只支持嵌套滚动( AppBarLayout滚动支持的要求),从Lollipop开始。在此之前,您必须使用实现NestedScrollingChild的视图,如RecyclerViewNestedScrollView

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31940908

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档