解决ConstraintLayout两个组件挤压问题

来源:互联网 发布:淘宝卖家工具源码 编辑:程序博客网 时间:2024/05/29 03:18
ConstraintLayout一行配置两个组件的时候,如果都是wrap_content,那么第一个如果太长就会把第二个挤掉,解决方法如下:
<TextView
    android:id=“@+id/titleView”
    android:layout_width=“0dp”  必须指定宽度为0,使得第一个textview自适应
    android:layout_height=“wrap_content”
    android:layout_marginLeft=“@dimen/job_detail_left_padding”
    android:layout_marginStart=“@dimen/job_detail_left_padding”
    android:layout_marginTop=“16dp”
    android:ellipsize=“end” 
    android:gravity=“center_vertical”
    android:maxLines=“1”
    android:text=”我是很长很长很长很长很长很长很长很长很长的一段文字“
    android:textColor=”#1A1A1A“
    android:textSize=”18sp“
    android:paddingRight=”9dp“
    card_view:layout_constraintHorizontal_bias=”0.0“这个主要是使得该view中文字靠左显示
    card_view:layout_constraintLeft_toLeftOf=”parent“ 需要同时指定左侧和右侧链
    card_view:layout_constraintRight_toLeftOf=”@+id/updateTimeView“
    card_view:layout_constraintTop_toTopOf="parent"/>

<TextView
    android:id="@+id/updateTimeView"
    android:layout_width="wrap_content" 必须是wrap_content,否则会把第一个TextView挤压掉
    android:layout_height="wrap_content"
    android:text=”我在后边不想被挤掉"
    android:textColor="#B3B3B3"
    android:textSize="@dimen/text_size_12sp"
    card_view:layout_constraintRight_toRightOf="parent"
    android:layout_marginRight="@dimen/job_detail_right_padding"
    card_view:layout_constraintLeft_toLeftOf="@+id/titleView"需要指定左侧链
    android:layout_marginLeft="8dp"
    card_view:layout_constraintBaseline_toBaselineOf="@+id/titleView"
    android:layout_marginEnd="@dimen/job_detail_right_padding"
    card_view:layout_constraintHorizontal_bias="1.0" />这个主要是使得该view中文字靠右显示