ConstraintLayout 作为 RecyclerView 项目

2024-04-26

I use ConstraintLayout as RecyclerView物品。但现在存在一些问题,真机上显示的和预览中不一样

recyclerView的item布局如下:

<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/foreground_item_undo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="horizontal"
    app:layout_constraintWidth_default="spread">

    <com.lsl.wordhelper.view.RoundBgTextView
        android:id="@+id/tv_item_icon"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginStart="8dp"
        android:gravity="center"
        android:padding="4dp"
        android:text="G"
        android:textColor="@android:color/white"
        android:textSize="30sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/tv_item_explain"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="释义:"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="@id/tv_item_original"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/tv_item_original"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="16dp"
        android:text="Good"
        android:textColor="@android:color/black"
        android:textSize="24sp"
        app:layout_constraintBottom_toTopOf="@id/tv_item_explain"
        app:layout_constraintLeft_toRightOf="@id/tv_item_icon"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/tv_item_translate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="很好"
        android:textColor="@android:color/black"
        android:textSize="16sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="@id/tv_item_original"
        app:layout_constraintTop_toBottomOf="@id/tv_item_explain" />

    <TextView
        android:id="@+id/tv_item_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:gravity="right"
        android:text="2018/01/19"
        android:textColor="@color/text_color_date"
        app:layout_constraintBottom_toBottomOf="@id/tv_item_original"
        app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>

In Android Studio preview . enter image description here

But on the phone
enter image description here

有什么问题?


更新适配器的 oncreateView :

//view is what we return from onCreateViewHolder
view.apply {
    this.layoutParams = RecyclerView.LayoutParams(
    ViewGroup.LayoutParams.MATCH_PARENT,
    ViewGroup.LayoutParams.WRAP_CONTENT
    )
}

这总是有效的。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ConstraintLayout 作为 RecyclerView 项目 的相关文章

  • 如何在GreenDao中实现表继承

    我一直在尝试创建一个数据库 其中所有表都继承某个元素 以便有可能拥有元数据 我在模型生成器的所有表声明中添加了这一行 public Entity addSuperEntity Schema schema Entity superEntity
  • CursorAdapter 破坏了 CHOICE_MODE_MULTIPLE 选项

    我有一个ListFragment 我在其中添加一个CursorAdapter to my ListView 并且我希望能够单击几行以使用上下文操作栏 我使用 SherlockActionbar 当我使用一个简单的ArrayAdapter 但
  • 如何查找 Android 上剩余的可用存储空间(磁盘空间)? [复制]

    这个问题在这里已经有答案了 我试图找出运行我的应用程序的 Android 手机上的可用磁盘空间 有没有办法以编程方式执行此操作 Thanks 示例 获取人类可读的大小 如 1 Gb 字符串内存 bytesToHuman totalMemor
  • 如何在 ubuntu 14.04 中保持 Android 模拟器始终位于最前面

    如何在 ubuntu 14 04 中保持 Android 模拟器始终位于最前面 我使用的是 Android Studio 2 1 1 和模拟器版本 25 1 6 在将 Android SDK Tools 更新到 25 1 6 之前它可以正常
  • 查看登录设备

    我想查看Log在设备上 即System out println 我可以查看DDMS但如何在运行时在设备屏幕上查看APK文件 还有一个适用于 Android 的 Logcat 应用程序 code google com p android ra
  • 模拟器的窗口比手机屏幕太大

    我做了一个小例子来测试我的Android环境 当我在AVD上启动执行时 它看起来太大了 就好像它是平板电脑屏幕一样 如何调整大小使其看起来像手机屏幕 Android Studio 2 2更新后就没有了Emulator Tab in Edit
  • Android 应用程序 Azure 依赖项 gradle 构建时出错

    我在 Android Studio 2 3 3 的 Gradle 同步中收到以下错误 错误 模块 com microsoft azure azure mobile android 3 3 0 依赖于一个或多个 Android 库 但它是一个
  • Glide:如何使用 Glide v4 调整 gif 大小并将其另存为文件?

    我想调整 gif 文件的大小并保存它 我尝试使用一些建议的方法 但这些方法给出了错误 后来我知道有些方法在 Glide 中已被弃用v4 byte bytes Glide with context asGif load url toBytes
  • Android 自定义对话框中的图标

    有没有一种方法可以在不使用 AlertDialog 方法的情况下在自定义对话框上设置图标 对话框有标题 但缺少漂亮的分隔线和设置图标的功能 但肯定有一种方法可以在不使用 AlertDialog 的情况下获得两者 您可以使用以下代码添加图标
  • 是否可以在 Flutter 中创建自定义快速设置图块?

    我搜索了 Flutter 文档并用谷歌搜索了这个 但结果为零 我正在开发我的第一个 Android Flutter 应用程序 我想为其创建一个自定义的快速设置图块 我的目标是牛轧糖及以上 我知道这在 Java 和 Kotlin 中是可能的
  • Android searchView下拉菜单屏幕宽度

    情况 我的 appcompat 工具栏中有一个 searchview 小部件 允许通过 sqlitedatabase 提供自定义建议 Problem 我无法将下拉建议列表扩展到屏幕的整个宽度 最好的情况下 列表宽度几乎是屏幕的宽度 除了左侧
  • 更改单击后退按钮上的 BottomNavigationView 图标

    在我的布局的底部有一个底部导航视图与三个片段 如果我单击后退按钮 片段将切换 但底部图标不会切换 我该如何修复它 addToBackStack 有效 也许您有一些关于美化代码的建议 在活动或片段中添加片段标签是一个好的做法吗 public
  • 使用 Android Intent 发送基于 HTML 的电子邮件正文

    我需要使用 android Intent extra 将基于 HTML 的内容发送到电子邮件应用程序 它接受一些标签 例如 br 但它没有显示任何锚链接或 h1 其显示像简单的文本 EDITED I have tried with gmai
  • 在 Android 谷歌地图中绘制 4K 折线

    我现在正在开发一个适用于 Android 设备的应用程序 主要功能是在地图上绘制折线以显示城市中每条街道的交通情况 不幸的是 当我绘制大约 3K 折线时 数量会根据屏幕尺寸和缩放级别而减少 我的地图变得非常慢 我没有提及绘制所有线条的时间
  • 应用程序被终止时无法处理 FCM 消息

    我一直在阅读各种教程 其他 SO 线程以及官方 Android 开发人员和 Firebase 文档 但无济于事 我已经尝试了几乎所有的方法 但我已经耗尽了精力和时间 因为我正在修复以前可以工作但现在不再工作的通知系统 我正在使用 Azure
  • android:如何显示TableLayout的边框

    我如何突出显示表格布局的边框 在使用以形状为背景的圆形 shape xml 时 必须有某种方法可以为您的表格布局提供边框 圆形 xml
  • 蓝牙连接;无法正确发送字符串

    当我需要将字符串从服务器蓝牙套接字发送到客户端蓝牙套接字时 我的程序遇到了麻烦 只要我一次只发送一个字符串 例如聊天 一切都可以正常工作 但是如果我需要在短时间内编写更多字符串 以交换信息 则字符串将不会与客户端代码分离 例如 如果我发送
  • Android - 减少位图绘制的内存使用量

    我的应用程序中有一张地图 显示了 Gowalla 的位置 我使用带有简单默认标记的 ItemizedOverlay 但在绘制项目时 我将默认标记替换为从 Gowalla 下载 9 并缓存在磁盘上 的位置图标 问题是 如果屏幕上有很多位置 例
  • 获取 Search.List 中的 ViewCount - Youtube 数据 API v3

    最近 我与youtube API v3 for Android I use 搜索列表 https developers google com youtube v3 docs search list当我想从关键字检 索视频列表时 我可以从结果
  • 在主表单之前显示登录表单

    我在表单之间导航时遇到问题 我使用 Delphi XE5 创建了一个 Android Firemonkey 移动应用程序 我目前有一个登录表单和主表单 现在我想要有关如何处理登录表单以显示在主表单之前的建议 在 项目选项 中的表单下 选择要

随机推荐