recyclerview内部的recyclerview 即使添加了行似乎也没关系,但是它什么也没显示。 像这样的许多问题已经问过并回答了,但我的却没有解决
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/fn_file_field_card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardElevation="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/fn_field_margin_right_and_left"
android:layout_marginTop="@dimen/fn_field_margin_top_or_bottom"
android:layout_marginRight="@dimen/fn_field_margin_right_and_left"
android:orientation="vertical">
<ir.tenthwindow.lbs.views.PersianTextView
android:id="@+id/fn_file_field_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="btn"
android:textColor="@color/black"
android:textSize="@dimen/fn_field_text_size"
android:textStyle="bold" />
<ir.tenthwindow.lbs.views.PersianTextView
android:id="@+id/fn_file_field_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_green"
android:gravity="center"
android:maxLines="1"
android:padding="10dp"
android:text="@string/upload_file"
android:textColor="@color/white"
android:textSize="@dimen/fn_field_text_size" />
<android.support.v7.widget.RecyclerView
android:id="@+id/fn_field_images_RecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="@dimen/fn_field_line_margin_top"
android:background="@color/fn_grey_line_border">
</View>
</LinearLayout>
</android.support.v7.widget.CardView>
提前感谢您
答案 0 :(得分:1)
如上所述,您需要一个布局管理器来使recyclerview正常工作。可以将其添加到xml中,也可以以编程方式添加。在xml中:
<android.support.v7.widget.RecyclerView
android:id="@+id/fn_field_images_RecyclerView"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
或以编程方式:
LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
yourRecyclerView.setLayoutManager(layoutManager);
请注意,如果需要网格布局,还可以使用GridLayoutManager。
答案 1 :(得分:1)
尝试将recyclerview的高度更改为match_parent
,而不是wrap_content
。
<android.support.v7.widget.RecyclerView
android:id="@+id/fn_field_images_RecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
&如果将适配器设置为wrap_content
,则适配器中的布局高度为match_parent
。
还要将LinearLayoutManager
设置为Vertical
方向。