[英]Recycler view is not rendering when width & height are set to 0dp
I have a simple layout, which contains a text view
, ImageView
, and a recycler view
, If i set recycler's view width & height to 0dp, and connects its constraint to parent, it does not render the recycler view.我有一个简单的布局,其中包含一个
text view
ImageView
和一个recycler view
,如果我将回收器的视图宽度和高度设置为 0dp,并将其约束连接到父级,它不会呈现回收器视图。
But if i define height in numbers then it works fine, and renders recyclerview
但是如果我用数字定义高度,那么它工作正常,并呈现
recyclerview
This is my code这是我的代码
<android.support.design.widget.CoordinatorLayout 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"
android:background="@color/blue"
tools:context=".activities.MyActivityV2">
<include layout="@layout/content_more_activity" />
</android.support.design.widget.CoordinatorLayout>
Inner Layout内部布局
<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"
tools:context=".activities.MyActivityV2"
tools:showIn="@layout/activity_more">
<ImageView
android:id="@+id/imageView23"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/logo" />
<TextView
android:id="@+id/tvLabelMore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="10dp"
android:letterSpacing="0.1"
android:text="MORE"
android:textAllCaps="true"
android:textColor="@color/white"
android:textSize="24dp"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="@+id/imageView23"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rvMoreItems"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView23" />
Class File Class 文件
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init();
generateDataForRecyclerView();
initRecyclerView();
}
private void init() {
rvMoreItems= findViewById(R.id.rvMoreItems);
}
private void generateDataForRecyclerView() {
MoreDataClass moreDataClass= new MoreDataClass();
moreDataClass.setLabel("AAA");
moreDataClass.setHeaderItem(true);
dataList.add(moreDataClass);
dataList.add(moreDataClass);
}
private void initRecyclerView() {
MoreAdapter moreAdapter= new MoreAdapter(this);
moreAdapter.setData(dataList);
rvMoreItems.setLayoutManager(new LinearLayoutManager(this));
rvMoreItems.setAdapter(moreAdapter);
}
Update this function check below.在下面更新此 function 检查。
private void initRecyclerView() {
MoreAdapter moreAdapter= new MoreAdapter(this);
rvMoreItems.setLayoutManager(new LinearLayoutManager(this));
rvMoreItems.setAdapter(moreAdapter);
moreAdapter.setData(dataList);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.