需求:LinearLayout
中嵌入RecyclerView
要显示全部内容,但内容的多少条数为未知的
第一步:包装一层RelativeLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/cash_coupon_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/distance_size_4"
android:paddingTop="@dimen/distance_size_4"
android:visibility="visible" />
</RelativeLayout>
第二步:Adapter的布局的最外层布局保证 android:layout_height="wrap_content"
是wrap_content
属性
方法源自https://my.oschina.net/ccmagic/blog/1929231实测有效。
另外还有方法为,没有试过
//在设置此属性即可,只有23以上的库有该方法
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setAutoMeasureEnabled(true);
网友评论