2016-03-21 15 views
0

I Symbolleiste im Inneren mit Imageview haben Kollabieren zu blättern und eine Listenansicht darzustellen Hier ist der Code:Listview nicht in der Lage

<?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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

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

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

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

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

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

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

    <ListView 
     android:id="@+id/listView_userDetails" 
     android:layout_width="match_parent" 
     android:layout_marginTop="20dp" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_height="match_parent" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="15dp" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

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

ich nicht in der Lage bin in der Listenansicht blättern und darüber hinaus wird die Symbolleiste nicht kollabiert . Können Sie mir auch sagen, wie man Farben abhängig von den Bildfarben automatisch auf die Werkzeugleiste setzt.

+0

P.S. Stellen Sie eine einzelne Frage in einer einzigen Frage. –

+0

Verwenden Sie ListView nicht mit CoordinatorLayout, da dies zu merkwürdigem Verhalten führen kann. Verwenden Sie Recyclerview anstelle von ListView. –

+0

Verwenden Sie recycleview anstelle von listview. Das ist schneller. –

Antwort

0

Ihr scrollbares Kind muss Nested Scrolling unterstützen. ListView unterstützt geschachteltes Scrollen erst ab 21+, daher müssen Sie RecyclerView verwenden.

0

Fügen Sie Ihre Listenansicht/Recyclingansicht unter NestedScrollView hinzu.
Ersetzen Sie Ihre Layout-Code mit

 <?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:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"><android.support.design.widget.AppBarLayout 
      android:id="@+id/appBarLayout_profilePage" 
      android:layout_width="match_parent" 
      android:layout_height="192dp" 
      android:fitsSystemWindows="true" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

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

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

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

      </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"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/listView_userDetails" 
      android:layout_width="match_parent" 
      android:layout_marginTop="20dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_height="match_parent" 
      android:divider="@android:color/transparent" 
      android:dividerHeight="15dp" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
    </android.support.v4.widget.NestedScrollView> 

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

Ich hoffe, es funktioniert.

+0

Bitte erwähnen Sie, was Sie in Ihrer Antwort geändert haben. –

+0

Ich habe die verschachtelte scrollView hinzugefügt, aber jetzt wird nur 1 Element in der Listenansicht angezeigt – Sarthak

+0

Versuchen Sie Recyclerview anstelle von ListView zu verwenden. Überprüfen Sie die aktualisierte Antwort. Ich denke es ist besser. –

0

Ich hatte das gleiche Problem konfrontiert und ich löste mit RecyclerView und der Grund ist wie von @Marius gesagt.

+1

Wie ist das eine Antwort? –

0

Sie können den folgenden Code auch in Ihrer XML-Layoutdatei hinzufügen.

<Listview 
    ............ 
    ............ 
    android:scrollbars=”vertical” 
    ........../>