android - 将可扩展 ListView 与 CollapsingToolbarLayout 一起使用时出现问题

标签 android expandablelistview

我有一个如下所示的布局。

enter image description here

在此布局底部添加可扩展布局后,会将我的内容推送到 CollapsingToolbarLayout 内并隐藏它,直到我向下滚动它为止。

您可以在 CollapsingToolbarLayout 布局下看到指向隐藏内容的箭头。仅留下“流派”显示

enter image description here

这是我下面的代码,我在这个示例中使用 CoordinatorLayout、CollapsingToolbarLayout、LinearLayout => https://github.com/chrisbanes/cheesesquare

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/detail_backdrop_height"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:fitsSystemWindows="true">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimaryDark"
                app:expandedTitleMarginStart="48dp"
                app:expandedTitleMarginEnd="64dp">

                <ImageView
                    android:id="@+id/moviebigimage"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop"
                    android:fitsSystemWindows="true"
                    app:layout_collapseMode="parallax" />

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:layout_collapseMode="pin" />

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

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

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:paddingBottom="24dp"
                android:paddingTop="24dp">



                <!-- I have other layouts here -->
<!--but i remove it so the post will not be too Long -->

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:paddingLeft="8dp"
                    android:paddingTop="10dp">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:paddingLeft="8dp"
                        android:orientation="vertical" >

                        <TextView
                            android:id="@+id/othercentres"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="Very Long text here"
                            android:paddingTop="7dp"
                            android:paddingRight="5dp"
                            android:textAppearance="@style/SmallTitle"
                            />

                    </LinearLayout>

                </LinearLayout>

                <View
                    android:layout_width="fill_parent"
                    android:layout_height="1dp"
                    android:layout_marginTop="10dp"
                    android:background="#cccccc"/>

                <!-- Expandable List -->
                <ScrollView
                    android:id="@+id/activity_expandable_scroll_view"
                    android:layout_width="match_parent"
                    android:layout_height="400dp"
                    android:fillViewport="true">
                    <ExpandableListView
                        android:id="@+id/laptop_list"
                        android:layout_width="match_parent"
                        android:layout_height="fill_parent" >
                    </ExpandableListView>
                </ScrollView>


            </LinearLayout>

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

        <android.support.design.widget.FloatingActionButton
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            app:layout_anchor="@id/appbar"
            app:layout_anchorGravity="bottom|right|end"
            android:src="@drawable/ic_video"
            android:layout_margin="@dimen/fab_margin"
            android:clickable="true"/>

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

请问我该怎么解决这个问题???

最佳答案

第 1 步:创建不可滚动的可展开 ListView

创建不可滚动的ExpandableListView

public class NonScrollExpandableListView extends ExpandableListView {

public NonScrollExpandableListView(Context context) {
    super(context);
}

public NonScrollExpandableListView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public NonScrollExpandableListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
            Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
    ViewGroup.LayoutParams params = getLayoutParams();
    params.height = getMeasuredHeight();
}
}

第 2 步:Xml 部分代码 添加滚动行为 app:layout_behavior="@string/appbar_scrolling_view_behavior"

<android.support.v4.widget.NestedScrollView   
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>

<view.customviews.NonScrollExpandableListView
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:background="@color/colorPrimary"
    android:id="@+id/fstt_elv_time_table"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipToPadding="false"
    />

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

关于android - 将可扩展 ListView 与 CollapsingToolbarLayout 一起使用时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33273859/

相关文章:

java - 需要帮助理解 getAcceptedIssuers 方法

android如何使用颜色选择器对话框

java - 安卓|如何在 ScrollView 中使用 ExpandableListView?

java - 'ExpandableListAdapter' 是抽象的;不能实例化

Android 可扩展列表子布局未正确展开?

java - 安卓 : import libraries Like PhotoView

java - 如何动态添加某个元素下方的相对布局

android - 如果 TouchWiz 源代码不作为开源提供,基于 TouchWiz 的 android ROMS 如何工作?

android - 单击 ExpanandableListView 子元素的打开对话框 fragment

ExpandableListView - onItemLongClick - getPackedPositionChild 始终返回 0