0

Ich habe ein Layout, das 3 cardviews darin enthält. Einer von ihnen hat statischen Inhalt und eine feste Größe, während die anderen drei dynamischen Inhalt enthält, der aus einer Listenansicht geladen wird.scrollen nicht möglich cardview mit Listenansichten

Ich bekomme scrollbaren Inhalt in den 3 cardviews, aber stattdessen möchte ich die Listenansichten fill_parent innerhalb der cardviews und die cardviews sollten stattdessen blättern. Hier ist mein Code-Schnipsel

<?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" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.animo.gita.activity.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

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

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" 
      android:orientation="vertical"> 

      <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" 
       android:layout_width="match_parent" 
       android:layout_height="100dp" 
       android:layout_marginBottom="8dp" 
       android:layout_marginLeft="8dp" 
       android:layout_marginRight="8dp" 
       android:layout_marginTop="8dp" 
       card_view:cardElevation="8dp"> 

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

        <TextView 
         android:id="@+id/commiter_name" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:textSize="16sp" 
         tools:text="animo93" /> 

        <TextView 
         android:id="@+id/days" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         tools:text="4 days ago" /> 

        <TextView 
         android:id="@+id/commit_name" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:textSize="18sp" 
         android:textStyle="bold" 
         tools:text="Added File Fragment" /> 

        <TextView 
         android:id="@+id/commit_desc" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:textStyle="italic" 
         tools:text="33 changed files with 506 additions and 42 deletions." /> 
       </LinearLayout> 

      </android.support.v7.widget.CardView> 

      <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="8dp" 
       android:layout_marginLeft="8dp" 
       android:layout_marginRight="8dp" 
       android:layout_marginTop="8dp" 
       android:layout_weight="1" 
       card_view:cardElevation="8dp"> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_marginBottom="8dp" 
        android:layout_marginLeft="8dp" 
        android:layout_marginRight="8dp" 
        android:layout_marginTop="8dp" 
        android:orientation="vertical"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 

         android:text="FILES CHANGED" 
         android:textSize="18sp" 
         android:textStyle="bold" /> 

        <ListView 
         android:id="@+id/changed_files_list" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent"></ListView> 
       </LinearLayout> 
      </android.support.v7.widget.CardView> 

      <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="8dp" 
       android:layout_marginLeft="8dp" 
       android:layout_marginRight="8dp" 
       android:layout_marginTop="8dp" 
       android:layout_weight="1" 
       card_view:cardElevation="8dp"> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_marginBottom="8dp" 
        android:layout_marginLeft="8dp" 
        android:layout_marginRight="8dp" 
        android:layout_marginTop="8dp" 
        android:orientation="vertical"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 

         android:text="FILES ADDED" 
         android:textSize="18sp" 
         android:textStyle="bold" /> 

        <ListView 
         android:id="@+id/added_files_list" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent"></ListView> 
       </LinearLayout> 

      </android.support.v7.widget.CardView> 

      <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="8dp" 
       android:layout_marginLeft="8dp" 
       android:layout_marginRight="8dp" 
       android:layout_marginTop="8dp" 
       android:layout_weight="1" 
       card_view:cardElevation="8dp"> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_marginBottom="8dp" 
        android:layout_marginLeft="8dp" 
        android:layout_marginRight="8dp" 
        android:layout_marginTop="8dp" 
        android:orientation="vertical"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 

         android:text="FILES RENAMED" 
         android:textSize="18sp" 
         android:textStyle="bold" /> 

        <ListView 
         android:id="@+id/renamed_files_list" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent"></ListView> 
       </LinearLayout> 

      </android.support.v7.widget.CardView> 

     </LinearLayout> 
</android.support.design.widget.CoordinatorLayout> 
+0

Kann jemand mir bitte eine Antwort für diese zur Verfügung stellen? – animo3991

Antwort

0

Wickeln Sie Ihre CardView's Behälter LinearLayout mit android.support.v4.widget.NestedScrollView für verschachtelte Scrollen.

Try this:

<?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" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.animo.gita.activity.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </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.support.v7.widget.CardView 
       android:layout_width="match_parent" 
       android:layout_height="100dp" 
       android:layout_marginBottom="8dp" 
       android:layout_marginLeft="8dp" 
       android:layout_marginRight="8dp" 
       android:layout_marginTop="8dp" 
       card_view:cardElevation="8dp"> 

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

        <TextView 
         android:id="@+id/commiter_name" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:textSize="16sp" 
         tools:text="animo93" /> 

        <TextView 
         android:id="@+id/days" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         tools:text="4 days ago" /> 

        <TextView 
         android:id="@+id/commit_name" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:textSize="18sp" 
         android:textStyle="bold" 
         tools:text="Added File Fragment" /> 

        <TextView 
         android:id="@+id/commit_desc" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:textStyle="italic" 
         tools:text="33 changed files with 506 additions and 42 deletions." /> 
       </LinearLayout> 

      </android.support.v7.widget.CardView> 

      <android.support.v7.widget.CardView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="8dp" 
       android:layout_marginLeft="8dp" 
       android:layout_marginRight="8dp" 
       android:layout_marginTop="8dp" 
       android:layout_weight="1" 
       card_view:cardElevation="8dp"> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_marginBottom="8dp" 
        android:layout_marginLeft="8dp" 
        android:layout_marginRight="8dp" 
        android:layout_marginTop="8dp" 
        android:orientation="vertical"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 

         android:text="FILES CHANGED" 
         android:textSize="18sp" 
         android:textStyle="bold" /> 

        <ListView 
         android:id="@+id/changed_files_list" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent"> 

        </ListView> 
       </LinearLayout> 
      </android.support.v7.widget.CardView> 

      <android.support.v7.widget.CardView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="8dp" 
       android:layout_marginLeft="8dp" 
       android:layout_marginRight="8dp" 
       android:layout_marginTop="8dp" 
       android:layout_weight="1" 
       card_view:cardElevation="8dp"> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_marginBottom="8dp" 
        android:layout_marginLeft="8dp" 
        android:layout_marginRight="8dp" 
        android:layout_marginTop="8dp" 
        android:orientation="vertical"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 

         android:text="FILES ADDED" 
         android:textSize="18sp" 
         android:textStyle="bold" /> 

        <ListView 
         android:id="@+id/added_files_list" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent"> 

        </ListView> 
       </LinearLayout> 

      </android.support.v7.widget.CardView> 

      <android.support.v7.widget.CardView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="8dp" 
       android:layout_marginLeft="8dp" 
       android:layout_marginRight="8dp" 
       android:layout_marginTop="8dp" 
       android:layout_weight="1" 
       card_view:cardElevation="8dp"> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_marginBottom="8dp" 
        android:layout_marginLeft="8dp" 
        android:layout_marginRight="8dp" 
        android:layout_marginTop="8dp" 
        android:orientation="vertical"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 

         android:text="FILES RENAMED" 
         android:textSize="18sp" 
         android:textStyle="bold" /> 

        <ListView 
         android:id="@+id/renamed_files_list" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent"> 

        </ListView> 
       </LinearLayout> 
      </android.support.v7.widget.CardView> 
     </LinearLayout> 
    </android.support.v4.widget.NestedScrollView> 
</android.support.design.widget.CoordinatorLayout> 
+0

Es gibt "ScrollView kann nur ein direktes Kind hosten" Fehler – animo3991

+0

Ich habe vergessen, 'LinearLayout' in' NestedScrollView' hinzuzufügen. ScrollView muss nur ein direktes Kind haben. – FAT

+0

Ich habe das auch versucht, aber dieses Mal die Kartenansichten nur Inhalt eingewickelt und füllte den Bildschirm nicht – animo3991

Verwandte Themen