android - 约束布局左右约束

标签 android layout android-constraintlayout

我有一个约束布局,当字符串足够长时,它会与右侧的元素重叠。示例代码是:

  <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

  <ImageView
    android:id="@+id/iconIv"
    android:layout_width="36dp"
    android:layout_height="36dp"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent"/>



  <TextView
        android:id="@+id/nameTv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toRightOf="@id/iconIv"
        app:layout_constraintTop_toTopOf="parent"/>

  <FrameLayout
    android:id="@+id/priceFl"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent">
  </FrameLayout>

 ...

enter image description here

然后我尝试 nameTv 像这样 app:layout_constraintRight_toLeftOf="@id/priceFl" 将右约束添加到右侧元素的左侧,这发生了:

enter image description here

有没有办法将此文本定位在图标和价格 View 之间?

最佳答案

试试这个

<TextView
        android:id="@+id/nameTv"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toRightOf="@id/iconIv"
        app:layout_constraintRight_toLeftOf="@+id/priceFl"
        app:layout_constraintTop_toTopOf="parent"/>

关于android - 约束布局左右约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48377768/

相关文章:

android - ListView 未出现/Android 布局

android - 如何将渐变定义为圆形progressBar

android - 以编程方式为 imageView 设置纵横比

android - ERROR : Failed to resolve: com. android.support.constraint :constraintlayout:1. 1.3 在项目结构对话框中显示受影响的模块:app

android - ProGuard 的 -whyareyoukeeping 在 Android Studio 中的输出在哪里?

android - android:gradle:如何复制文件?发出将文件设置为可读或读取的问题

android - Android开发中如何正确处理View State

android - 无法更改 ImageView 的可见性

html - dom/css : inclose multiple 100% container into a container larger then the viewport(100%)

Android ImageView 在使用 layout_above 时消失