【发布时间】:2018-11-21 06:18:08
【问题描述】:
它在旧项目中运行良好用java编写
当用 kotlin 编写相同的东西时,它不起作用...
问题 RecyclerView 项目 高度太大
lateinit var mImageProcessedRecyclerViewAdapater:ImageProcessedRecyclerViewAdapater
lateinit var mImageContainerAfterProcess: RecyclerView
//初始化适配器和itemdecoration
mImageContainerAfterProcess= findViewById(R.id.ImageContainerAfterProcess)
mImageContainerAfterProcess.addItemDecoration(RecyclerViewItemDecoration(16))
mImageContainerAfterProcess.layoutManager=StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
mImageContainerAfterProcess.adapter=mImageProcessedRecyclerViewAdapater
项目视图xml文件
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/processedImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
包含recyclerview的Activity布局文件
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activitis.ImageProcess">
// layout height and width is match_constraint
<android.support.v7.widget.RecyclerView
android:id="@+id/ImageContainerAfterProcess"
android:layout_width="0dp"
android:layout_height="0dp"
tools:listitem="@layout/processd_image_item_view"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout>
我不知道我做错了什么
通过布局检查器捕获输出
我的旧项目输出
【问题讨论】:
-
发布你的recyclerview xml完整代码
-
@sasikumar 发布
-
这两个 ConstraintLayouts 都是不必要的,因为 RecyclerView 和 ImageView 都是其父级的唯一子级。它们可以是根元素。另外,尝试将 RecyclerView 的宽度和高度固定为 match_parent,并将 ImageView 的宽度设置为 match_parent。让我知道这是否有效。
-
@RahulKumar 感谢您的评论先生,但它不起作用
标签: android android-layout android-recyclerview kotlin staggered-gridview