0

嘿,我對android編程有點新,但我似乎無法讓我的viewpager中的回收視圖工作。我正在使用帶有tablayout的viewpager,並且在其中一個頁面內部,我有一個recyclerview,其中包含每個卡片視圖中的動態創建的內容(每個卡片視圖將根據內部內容具有不同的高度)。我現在遇到的問題是,我的recycleriew的高度只能延伸到viewpager的高度,即使有時我的recyclerview中的cardview也有太多內容不適合viewpager屏幕。viewpager裏面的Recyclerview只能擴展viewpager的長度

Example

正如你可以從圖片中看到,我cardview已採取了整個屏幕,但我有我用來創建cardview我鍛鍊列舉一些練習,他們被切斷..

下面是我爲包含我的看法尋呼機中,XML爲viewpager片段的活性XML,也爲我的cardview

活動的XML與我viewpager

<android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/view" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 


    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:id="@+id/view"> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabMode="fixed" 
      app:tabGravity="fill"/> 

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

</RelativeLayout> 

與recyclerview

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.example.davidyuan7536.workoutlog.LogFragment" 
    android:orientation="vertical"> 

       <android.support.v7.widget.RecyclerView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:id="@+id/homeFeedRecycleView" /> 

</LinearLayout> 

cardview的recyclerview

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="match_parent" 
    android:padding="16dp" 
    > 

    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/cv" 
     > 

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

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:padding="16dp" 
       android:background="@color/homeFeedUserHeaderBackground"> 

       <ImageView 
        android:layout_width="80dp" 
        android:layout_height="80dp" 
        android:id="@+id/homeFeedUserAvatar" 
        android:layout_alignParentLeft="true" 
        android:layout_alignParentTop="true" 
        android:layout_marginRight="16dp" 
        android:src="@drawable/profile_icon"/> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/homeFeedUserName" 
        android:layout_toRightOf="@+id/homeFeedUserAvatar" 
        android:layout_alignParentTop="true" 
        android:textSize="20sp" 
        android:text="User Name" 
        android:singleLine="true" 
        android:ellipsize="end" 
        android:layout_marginRight="10dp" 
        android:textColor="@color/textColorPrimary"/> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/homeFeedWorkoutTitle" 
        android:layout_toRightOf="@+id/homeFeedUserAvatar" 
        android:layout_below="@+id/homeFeedUserName" 
        android:text="Workout Titile" 
        android:layout_marginTop="10dp" 
        android:layout_marginRight="10dp" 
        android:textSize="15sp" 
        android:textColor="@color/textColorPrimary"/> 

      </RelativeLayout> 



      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:id="@+id/homeFeedExercisesContainer" 
       android:paddingBottom="10dp"> 



      </LinearLayout> 

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

</LinearLayout> 
+0

你是說回收商視圖不滾動到其他卡片視圖? – CodeCody

+0

@CodeCody不是,而是裏面的cardviews被切斷。正如在更多的內容,應該顯示,但它沒有.. –

回答

1

內部viewpager片段消除外LinearLayout圍繞CardView

它有android:layout_height="match_parent"這是造成您的問題,它只有CardView作爲一個孩子,所以它不是必要的。