使用带有CollapsingToolbarLayout的可扩展列表视图的问题

时间:2015-10-22 05:19:44

标签: 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>

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

2 个答案:

答案 0 :(得分:4)

第1步:创建不可滚动的可展开列表视图

创建不可滚动的ExpandableListView

if let preNotifCount = self.cmmn.getPreviousNotofication {
      //business logic
}

第2步:Xml零件代码 添加滚动行为      应用程式:layout_behavior =&#34; @串/ appbar_scrolling_view_behavior&#34;

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();
}
}

答案 1 :(得分:0)

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

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

在你的java代码中

<div class='row'>
  <div class="item">
    <div class="sub-item"></div>
    <div class="sub-item"></div>
    <div class="sub-item"></div>
    <div class="sub-item"></div>
    <div class="sub-item"></div>
  </div>
  <div class="item">
    <div class="sub-item"></div>
    <div class="sub-item"></div>
    <div class="sub-item"></div>
    <div class="sub-item"></div>
    <div class="sub-item"></div>
  </div>
</div>

多数人全部!!!