2017-07-01 82 views
0

現在我正在使用一個簡單的RecyclerView應該顯示在TextView下。但是,當我用更多的項目填充RecyclerView時,它會被切斷,不會向下滾動。我從RecyclerViews中得到的記憶是,當我涉及到滾動時,我所做的每個實現基本上都是開箱即用的。RecyclerView不會向下滾動,如果有很多項目

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
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" 
tools:context="david.projectclouds.MainActivity" 
tools:showIn="@layout/app_bar_main"> 


<TextView 
    android:id="@+id/Date" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingBottom="@dimen/_20sdp" 
    android:paddingLeft="@dimen/_20sdp" 
    android:paddingTop="@dimen/_20sdp" 
    android:textAllCaps="true" 
    android:textColorLink="@color/colorAccent" 
    android:textSize="30sp" 
    android:typeface="sans" 
/> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/recycler_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:layout_constraintTop_toBottomOf="@+id/Date" 

    android:scrollbars="vertical" 
/> 
</android.support.constraint.ConstraintLayout> 

這是我目前的主要活動XML。告訴我是否需要添加更多代碼。

+0

機器人:layout_height = 「WRAP_CONTENT」 應爲 「match_parent」? –

+0

然後它繪製了我的textView。問題仍然存在。我已經多次嘗試過 – Nephilim

+0

您是否爲recyclerView設置了LayoutManager? –

回答

2

嘗試使用限制

<android.support.v7.widget.RecyclerView 
    android:id="@+id/recycler_view" 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:layout_marginBottom="8dp" 
    android:layout_marginLeft="8dp" 
    android:layout_marginRight="8dp" 
    android:layout_marginTop="8dp" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toBottomOf="@+id/Date" 
    android:layout_marginStart="8dp" 
    android:layout_marginEnd="8dp" /> 
+0

我只是決定使用RelativeLayout,但是謝謝。 – Nephilim

相關問題