将可扩展列表视图与 CollapsingToolbarLayout 结合使用时出现问题

Issues using Expandable List view with CollapsingToolbarLayout

我有一个看起来像这样的布局。

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

在CollapsingToolbarLayout布局下,可以看到指向隐藏内容的箭头。只留下 "Genre" 显示

下面是我的代码,我在这个例子之后使用 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>

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

我的问题终于得到了答案,经过数小时的研究,这似乎只是一行代码。

可扩展视图似乎始终默认设置为聚焦在屏幕上。所以我只需要将 setFocus 设置为 false

在您的 java 代码中

expListView = (ExpandableListView) findViewById(R.id.expanndableViewId);
expListView.setFocusable(false);

就这些了!!!

第 1 步:创建 non-scrollable 可扩展列表视图

创建non-scrollableExpandableListView

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>