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

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

 ...

android - 约束布局左右约束-LMLPHP

然后,我尝试给TV命名,以像app:layout_constraintRight_toLeftOf="@id/priceFl"一样在右边元素的左边添加右边约束,并发生了这种情况:

android - 约束布局左右约束-LMLPHP

有没有办法在图标和价格 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/

10-11 22:49
查看更多