首先,我知道舊版本庫中的Recycler問題。我目前的lib版本是24.2.1。RecyclerView with ScrollView wrap_content問題
我想製作一個模板,其中包含有關該項目的基本信息,以及該信息下方的評論列表。這個評論列表必須包含它的內容,並且必須與它的父項一起滾動,所以它應該是一個大視圖。
我試圖用下面的代碼來完成它,但RecyclerView並沒有包裝內容,而不是它在屏幕底部有一小部分。
<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:orientation="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="50dp">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/news_layout_header_repost"/>
<LinearLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/cardview_inner_margin"
android:layout_marginEnd="@dimen/cardview_inner_margin"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:id="@+id/repostTextLayout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
</LinearLayout>
<Button
android:id="@+id/loadComments"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</ScrollView>
</LinearLayout>
你能幫我嗎?
UPDATE 終於找到了解決辦法。最好使用Relative佈局。不知道爲什麼這個問題的LinearLayout來了,但下面的XML結構的工作:
<ScrollView>
<RelativeLayout>
<LinearLayout/>
<RecyclerView/>
</RelativeLayout>
</ScrollView>
你找到任何答案,我也有同樣的問題。 – YBDevi