美文网首页
ConstraintLayout TextView 自适应 s

ConstraintLayout TextView 自适应 s

作者: JayQiu | 来源:发表于2023-03-30 19:03 被阅读0次
水平偏移 属性 app:layout_constraintHorizontal_bias

app:layout_constraintHorizontal_bias="0"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constrainedWidth="true"

使用 app:layout_constraintHorizontal_bias 的前提 , 必须先设置水平方向的约束
//将 被约束组件 的 左侧 约束到 目标组件 的左侧
app:layout_constraintLeft_toLeftOf
//将 被约束组件 的 左侧 约束到 目标组件 的右侧
app:layout_constraintLeft_toRightOf

//将 被约束组件 的 右侧 约束到 目标组件 的左侧
app:layout_constraintRight_toLeftOf
//将 被约束组件 的 右侧 约束到 目标组件 的右侧
app:layout_constraintRight_toRightOf


//将 被约束组件 的 开始 约束到 目标组件 的 结束
app:layout_constraintStart_toEndOf
//将 被约束组件 的 开始 约束到 目标组件 的 开始
app:layout_constraintStart_toStartOf

//将 被约束组件 的 结束 约束到 目标组件 的 开始
app:layout_constraintEnd_toStartOf
//将 被约束组件 的 结束 约束到 目标组件 的 结束
app:layout_constraintEnd_toEndOf

链布局 ConstraintLayout Chain

app:layout_constraintHorizontal_chainStyle="packed"

app:layout_constrainedWidth="true" 属性,是按约束去限制宽度

<androidx.constraintlayout.widget.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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="6dp">
            <ImageView
                android:id="@+id/work_record_img"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_launcher"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
            <TextView
                android:id="@+id/tv_user_list_name"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                app:layout_constrainedWidth="true"
                android:ellipsize="end"
                android:singleLine="true"
                android:text="AmlyAminAmlyAminilyAmlyAminAmlyAminilyAmlyAminilyilyAmlyAminilyily"
                app:layout_constraintHorizontal_bias="0"
                app:layout_constraintHorizontal_chainStyle="packed"
                android:textColor="@color/white"
                android:textSize="16sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toRightOf="@id/work_record_img"
                app:layout_constraintRight_toLeftOf="@id/work_record_username"
                app:layout_constraintTop_toTopOf="parent"
                />

            <TextView
                android:id="@+id/work_record_username"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="6dp"
                android:text="test1"
                android:textColor="@color/white"
                android:textSize="18dp"
                app:layout_constraintLeft_toRightOf="@+id/tv_user_list_name"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="@id/tv_user_list_name" />

    </androidx.constraintlayout.widget.ConstraintLayout>

相关文章

网友评论

      本文标题:ConstraintLayout TextView 自适应 s

      本文链接:https://www.haomeiwen.com/subject/rijcddtx.html