约束布局 - Textview 在尺寸增大时会与其他视图重叠

2024-01-26

上图显示了我想要的视图的样子。 问题是,当上重力文本尺寸增加时,它会将图像推离视图。我尝试使用障碍,但无法使其发挥作用。 下图显示了我在实现这一目标方面已经走了多远。但现在的问题是图像总是卡在最后。但我希望它位于重力文​​本旁边,当该文本增加时,它应该卡在末尾,并且重力文本的高度应该增加。

<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/constraintLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="@dimen/dp_4">

            <TextView
                android:id="@+id/last_msg_tv"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginBottom="8dp"
                android:textAlignment="viewStart"
                android:textColor="@color/color_grey_3"
                android:textSize="@dimen/sp_12"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="@+id/barrier9"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="@+id/title_tv"
                app:layout_constraintTop_toBottomOf="@+id/title_tv"
                tools:text="In the future, Earth is slowly becoming uninhabitable. Ex-NASA pilot Cooper, along with a team of researchers, is sent on a planet exploration mission to report which planet can sustain life." />

            <TextView
                android:id="@+id/title_tv"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:textColor="@color/color_grey_2"
                android:textSize="@dimen/sp_16"
                android:textStyle="bold"
                app:layout_constraintEnd_toStartOf="@+id/imageView4"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                tools:text="Alpha CapriCod A" />

            <ImageView
                android:id="@+id/imageView4"
                android:layout_width="@dimen/dp_24"
                android:layout_height="@dimen/dp_24"
                android:layout_marginEnd="8dp"
                android:tint="@color/color_grey_5"
                app:layout_constraintEnd_toStartOf="@+id/user_count_tv"
                app:layout_constraintTop_toTopOf="@+id/title_tv"
                app:srcCompat="@drawable/mutiple_user_img" />

            <TextView
                android:id="@+id/user_count_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                app:layout_constraintBottom_toBottomOf="@+id/imageView4"
                app:layout_constraintEnd_toEndOf="@+id/barrier9"
                app:layout_constraintTop_toTopOf="@+id/imageView4"
                tools:text="1000" />

            <android.support.constraint.Barrier
                android:id="@+id/barrier9"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:barrierDirection="left"
                tools:layout_editor_absoluteX="387dp"
                tools:layout_editor_absoluteY="8dp" />

        </android.support.constraint.ConstraintLayout>

    </android.support.v7.widget.CardView>

</android.support.constraint.ConstraintLayout>

你能做的就是把title_tv (with wrap_content宽度),imageView4 and user_count_tv在水平链中packed风格和偏见0让它们向左对齐。当。。。的时候title_tv扩展,你需要使用app:layout_constrainedWidth="true"以防止它将其他视图推出界限。约束应该是这样的:

<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/constraintLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="4dp">

            <TextView
                android:id="@+id/last_msg_tv"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:textAlignment="viewStart"
                android:textSize="12sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="@id/title_tv"
                app:layout_constraintTop_toBottomOf="@id/title_tv"
                tools:text="In the future, Earth is slowly becoming uninhabitable. Ex-NASA pilot Cooper, along with a team of researchers, is sent on a planet exploration mission to report which planet can sustain life." />

            <TextView
                android:id="@+id/title_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:textSize="16sp"
                android:textStyle="bold"
                app:layout_constraintHorizontal_bias="0"
                app:layout_constraintHorizontal_chainStyle="packed"
                app:layout_constrainedWidth="true"
                app:layout_constraintEnd_toStartOf="@id/imageView4"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                tools:text="Alpha CapriA" />

            <ImageView
                android:id="@+id/imageView4"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_marginEnd="8dp"
                app:layout_constraintEnd_toStartOf="@id/user_count_tv"
                app:layout_constraintStart_toEndOf="@id/title_tv"
                app:layout_constraintTop_toTopOf="@id/title_tv"
                app:srcCompat="@android:drawable/btn_star" />

            <TextView
                android:id="@+id/user_count_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                app:layout_constraintBottom_toBottomOf="@id/imageView4"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@id/imageView4"
                app:layout_constraintTop_toTopOf="@+id/imageView4"
                tools:text="1000" />

        </android.support.constraint.ConstraintLayout>

    </android.support.v7.widget.CardView>

</android.support.constraint.ConstraintLayout>

Result:

并且标题更长:

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

约束布局 - Textview 在尺寸增大时会与其他视图重叠 的相关文章

随机推荐

  • 遵守标准有多重要?

    对于像 C 这样的语言来说 标准的存在是必须的 好的编译器会尽最大努力 至少是大多数好的编译器 来遵守 许多编译器都有语言扩展 其中一些是标准允许的 有些则不允许 后一种例子有2个 gcc 的 typeof 微软的编译器允许纯虚函数声明同时
  • 将原始 Markdown 文本传递给 Jade

    我正在尝试我的第一个 Node jsExpress http expressjs com 应用程序 正如每个程序员都知道的那样 在测试新框架时您应该构建的第一件事就是博客 不管怎样 我想用 Markdown 写文章 然后在视图中渲染它 我看
  • 避免循环内的条件和函数调用

    我有一个看起来像这样的代码 void function int parameter for a big loop double a for a big loop double b double value if parameter 1 va
  • Python + MySQLdb 执行许多

    我正在使用 Python 及其 MySQLdb 模块将一些测量数据导入 Mysql 数据库 我们拥有的数据量相当大 目前大约有 250 MB 的 csv 文件 未来还会有更多 目前我使用cursor execute 导入一些元数据 这不是问
  • kubectl 端口转发和代理之间的区别

    kubectl proxy and kubectl port forwarding对我来说看起来相似且令人困惑 它们的主要区别和用例是什么 正如 How kubectl port forward works https stackoverf
  • 在 Java 中使用命名空间创建 XML 文档

    我正在寻找可以构造使用命名空间的 XML 文档的示例 Java 代码 我似乎无法用我的正常方式找到任何东西最喜欢的工具 http www google com所以希望有人能够帮助我 有多种方法可以做到这一点 仅举几个例子 Using XOM
  • 如何将react应用程序导出为纯静态html

    就像标题一样 我有一个由reactJS编写的登陆页面 它很小 我想导出为纯静态html 我已经研究过 但没有找到任何解决方案 I used webpack https webpack js org 生成静态 html 和 javascrip
  • Rails3 gem:acts_as_something

    我正在尝试将一些常见代码提取到 gem 中 我在想acts as something是简单重用的好策略 有没有一个很好的教程来讨论这个关于rails3 gems 的问题 我发现了几个讨论rails2的 例如http guides rubyo
  • 如何忽略转义\ python列表?

    我想忽略以下代码中的转义字符 gt gt gt a gt gt gt print a 我想输出像 有什么办法可以做到这一点吗 Using string escape unicode escape编码 参见Python 特定编码 http d
  • React - 动态渲染一定数量的组件

    我想根据用户获得的积分数显示组件星号 MUI 组件 的数量 this state points 我不知道该怎么做 import React Component from react import Star from material ui
  • 使用拼凑时如何减少图之间的空间

    大家好 我正在使用一个小数据框来构建一些图ggplot2 我的数据框是df我把它包括为dput 在最后 我有情节 当我使用时问题出现patchwork 我希望最终的图没有空格 以便中间的线 即轴 可以将图连接在一起 这是代码 library
  • ITfoxtec SAML 2.0:配置 AWS SSO 时出现 InvalidSignatureException

    我有一个小型测试应用程序 已成功与 Okta 作为 IdP 集成 我还设置了 AWS SSO 来充当 IdP 当我将应用程序切换为使用 AWS SSO 时 出现以下错误 ITfoxtec Identity Saml2 Cryptograph
  • 测试对象是否实现接口

    以前可能有人问过这个问题 但快速搜索只提出了与 C 相同的问题 看这里 https stackoverflow com questions 410227 test if object implements interface 我基本上想做的
  • 根据另一个值的聚合查询唯一值,同时完全根据第三个值进行分组

    所以我知道这个问题并不是一个新问题 但我正在努力解决这个问题并了解处理此类情况的最佳方法 假设我有一个假设的表 X 如下所示 GroupID ID identity SomeDateTime 1 1000 1 1 01 1 1001 2 2
  • C 中的 OO 多态性、别名问题?

    我和一位同事正在尝试实现一个简单的多态类层次结构 我们正在开发嵌入式系统 并且仅限于使用 C 编译器 我们有一个基本的设计思想 可以在没有警告的情况下进行编译 Wall Wextra fstrict aliasing pedantic 并在
  • iOS 8 UITabBarController 和 UINavigationController 的旋转问题

    我在使用 iOS8 时遇到一个问题 这里我有我的视图层次结构 窗口 gt UITabBarController gt 2 个选项卡 Tab 1 gt UINavigationController1 gt UIViewController1
  • 通过 set/get 方法修改类

    尝试通过 get set 方法修改类中的对象 我无法理解如何仅使用 get set 方法来更改值 预期输出 输出 89 实际输出 输出 0 include
  • 如何在 Web 应用程序中获取客户端计算机的 Mac 地址

    我必须获取运行我的网站的客户端 PC 的 Mac 地址 那么如何获取客户端计算机的 Mac 地址 而不是托管网站的服务器的 Mac 地址 我需要与 IE Firefox Safari 和 Chrome 兼容的脚本 实现这一点的唯一方法是使用
  • 如何在 Cassandra 中将批处理语句和 LWT 作为事务执行

    我有两个模型如下的表 CREATE TABLE IF NOT EXISTS INV CODE TEXT PRODUCT CODE TEXT LOCATION NUMBER TEXT QUANTITY DECIMAL CHECK INDICA
  • 约束布局 - Textview 在尺寸增大时会与其他视图重叠

    上图显示了我想要的视图的样子 问题是 当上重力文本尺寸增加时 它会将图像推离视图 我尝试使用障碍 但无法使其发挥作用 下图显示了我在实现这一目标方面已经走了多远 但现在的问题是图像总是卡在最后 但我希望它位于重力文 本旁边 当该文本增加时