关于TextView在ConstraintLayout出现展示不全

本文介绍在使用ConstraintLayout时,如何确保TextView内的文字即使数量未知也能完整显示的方法。通过给ImageView和TextView添加特定属性,可以实现内容的自适应布局,避免文字被截断。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        在这里记录下在使用ConstraintLayout约束布局的时候如何有像这样的布局如下图,如果TextView的字数是无法预知的,那么可能会出现有一部分字无法显示。解决方案如下:添加相应的属性

        给左边的ImageView添加属性:  app:layout_constrainedWidth="true"
                                                            app:layout_constraintBottom_toBottomOf="parent"
                                                            app:layout_constraintHorizontal_bias="0"
                                                            app:layout_constraintHorizontal_chainStyle="packed"
                                                            app:layout_constraintLeft_toLeftOf="parent"
                                                            app:layout_constraintRight_toLeftOf="@+id/tv_map_name"
                                                            app:layout_constraintTop_toTopOf="parent"

       给右边的TextView添加属性:app:layout_constrainedWidth="true"
                                                      app:layout_constraintLeft_toRightOf="@+id/icon_photo"
                                                      app:layout_constraintRight_toRightOf="parent"
                                                      app:layout_constraintTop_toTopOf="parent"

     如果两个控件展示的内容是相反的,对于的属性也一样。

      下面是具体的代码:测试成功有效


  <ImageView
                android:id="@+id/icon_photo"
                android:layout_width="100dp"
                android:layout_height="100dp"
                app:layout_constrainedWidth="true"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintHorizontal_bias="0"
                app:layout_constraintHorizontal_chainStyle="packed"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toLeftOf="@+id/tv_map_name"
                app:layout_constraintTop_toTopOf="parent" />

            <android.support.v7.widget.AppCompatTextView
                android:id="@+id/tv_map_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="测试是否能展示完全,这句是测试代码语言"
                android:textColor="@color/textColor"
                android:textSize="14sp"
                app:layout_constrainedWidth="true"
                app:layout_constraintLeft_toRightOf="@+id/icon_photo"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

逍遥Y

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值