0

我正在實施一個應用程序ExpandableListviewFragment,ViewpagerCollapsingToolbarLayoutExpandableListView無法正常工作

但我有一個問題。我的ExpandableListview有錯誤的行爲。其餘的項目被削減。當我點擊TabLayout後面顯示的頂部項目下方的項目時。

代碼中的錯誤是什麼?謝謝

main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:fitsSystemWindows="true" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appBar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    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" 
     android:fitsSystemWindows="true" 
     app:expandedTitleMarginStart="30dp" 
     app:expandedTitleMarginEnd="25dp" 
     app:expandedTitleTextAppearance="@style/HeaderTitleStyle" 
     app:contentScrim="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

     <ImageView 
      android:id="@+id/background" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:adjustViewBounds="true" 
      android:fitsSystemWindows="true" 
      app:layout_collapseMode="parallax" 
      android:src="@drawable/img_oficinas"/> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:minHeight="?attr/actionBarSize" 
      android:background="@android:color/transparent" 
      app:theme="@style/ToolbarColoredBackArrow" 
      app:layout_collapseMode="pin"/> 

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

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:background="@color/colorAccent" 
     app:tabTextColor="@color/tabs_text_selector" 
     app:tabIndicatorHeight="3dp" 
     app:tabIndicatorColor="@android:color/white"/> 

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

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

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

fragment.xml之

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fillViewport="true"> 

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

    <ExpandableListView 
     android:id="@+id/expandableListView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:groupIndicator="@null" 
     android:background="@android:color/white" 
     android:dividerHeight="0dp" 
     android:divider="@android:color/white" /> 

</LinearLayout> 
</android.support.v4.widget.NestedScrollView> 
+0

你正在得到什麼類型的錯誤? – Madhur

+0

@Madhur下面的項目被切斷,當點擊下面的項目時,上面的項目出現在Tablayout後面 – IMS

+0

設置固定的高度和寬度 – Madhur

回答

0

CoordinatorLayoutScrollingViewBehavior僅適用於支持嵌套滾動(EXP RecyclerView)意見工作。 ExpandableListView默認不支持,所以CoordinatorLayout沒有正確處理ExpandableListView的位置。

對於API> 21您可以通過獲得這種行爲:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
    setNestedScrollingEnabled(true); 
} 

否則,您可以切換到自定義RecyclerViewExpandableRecyclerView