当前位置: 首页 > 知识库问答 >
问题:

使用StaggedGridLayoutManager[Android/Kotlin]的recyclerview中的ImageView高度过大

璩浩广
2023-03-14

它在用java编写的旧项目中运行良好

当相同的东西写在kotlin它不工作...

回收问题查看项目高度过大

lateinit var mImageProcessedRecyclerViewAdapater:ImageProcessedRecyclerViewAdapater
lateinit var mImageContainerAfterProcess: RecyclerView

//初始化适配器和项目装饰

    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的活动布局文件

<?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>

我找不到我做错了什么

通过布局检查器捕获输出

我的旧项目输出

共有3个答案

麻和雅
2023-03-14

你的图像视图应该是这样的

   <ImageView
    android:id="@+id/processedImage"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:padding="2dp"
    android:scaleType="fitXY"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />
翟承志
2023-03-14

wrap\u内容与约束布局的行为方式不同。要实现所需,您需要将以下代码添加到您的图像视图中,并将其宽度和高度设置为0dp

app:layout_constraintWidth_default="wrap"
app:layout_constraintHeight_default="wrap"

贲绪
2023-03-14

尝试将其添加到您处理的ImageImageView中。

android:scaleType="centerCrop"
android:adjustViewBounds="true"
//use centerCrop to fill staggered view or centerInside to avoid cropping.
 类似资料:
  • 我按照以下指南使用网格视图在图库中插入图像:http://developer . Android . com/guide/topics/ui/layout/GridView . html 我编辑了imageadapter代码,如下所示: } 这是img_gallery个 xml 这是主要布局: 问题是,当我调整应用程序时,imageview有很多顶部和底部填充。我也尝试在xml中将其设置为0,但它

  • 使用StaggedGridLayoutManager/GridLayoutManager如何使网格项在垂直方向上具有两个跨距,在水平方向上具有两个跨距?

  • 这就是我尝试过的 上的第一个错误: 上的第二个错误: 注释类目标不需要类型参数 第二次时的第三个错误: 这里怎么了?或者还有其他的解决办法吗??

  • 本文向大家介绍Android 使用SearchView过滤RecyclerView中的项目,包括了Android 使用SearchView过滤RecyclerView中的项目的使用技巧和注意事项,需要的朋友参考一下 示例 添加filter方法RecyclerView.Adapter: itemsCopy在适配器的构造函数中初始化。itemsCopy.addAll(items) 如果您这样做,只需f

  • 我写我的第一个应用程序在静态编程语言后,与Android的3年经验。只是困惑于如何利用itemClickListener与静态编程语言回收视图。 我已经尝试了trait(edit: now界面)方法,非常Java 这似乎很多余,所以我尝试了内部类方法: 然后设置适配器的click listener,如下所示: 但我仍然不满意,因为我认为可能有更好、更干净的方法。我试图实现这样的目标:Recycle

  • 我希望ImageView的宽度由父级设置,高度应该是方面比例。原因是接下来显示的是一个TextView,我想把它放在ImageView下面。 我可以得到图像显示正确使用 因为围绕这一切的RelativeLayout没有任何帮助。还尝试了FrameLayout和LinearLayout,但失败了。 有什么想法吗?