美文网首页
Android 实现textview在一定宽度内自适应宽度

Android 实现textview在一定宽度内自适应宽度

作者: 银弹星空 | 来源:发表于2022-03-28 17:18 被阅读0次

解决问题

view跟在textview的右边,view宽度固定,textview自适应宽度,但textview 加view宽度刚好到达父view宽度时,如果textview内容还没显示完应该显示省略号;就是textview宽度自适应到一定宽度后就不能再增长了。
image.png
<android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
 
        <TextView
            android:id="@+id/tvs"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:maxLines="1"
            android:textSize="24sp"
            app:layout_constrainedWidth="true"
            app:layout_constraintEnd_toStartOf="@+id/view"
            app:layout_constraintHorizontal_bias="0"
            app:layout_constraintHorizontal_chainStyle="packed"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:text="我是内容我是内容" />
 
        <View
            android:id="@+id/view"
            android:layout_width="80dp"
            android:layout_height="30dp"
            android:background="#f00"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toEndOf="@+id/tvs" />
 
    </android.support.constraint.ConstraintLayout>

注意

ConstraintLayout中的约束条件是否完整,如果不完整会提示报错,运行崩溃
This view is not constrained vertically: at runtime it will jump to the top unless you add a vertical constraint less…
水平垂直约束都要添加
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"

相关文章

  • Android 实现textview在一定宽度内自适应宽度

    解决问题 view跟在textview的右边,view宽度固定,textview自适应宽度,但textview 加...

  • 约束布局ConstraintLayout

    宽度自适应 实现TextView左右两边对齐,并且宽度自适应。当然文本不能太长,常见的是登录页: 代码如下: 注意...

  • TextView宽度自适应

    转载于 https://ask.csdn.net/questions/767643 https://img-ask...

  • CSS自适应布局

    今天小编介绍自适应布局实现方法的demo,1)左侧固定宽度,右侧自适应,随着窗口的宽度而变化;2)右侧固定宽度,左...

  • 自定义View

    View测量宽度自适应TextView 高度测量、复用View布局热词墙 高度自适应View绘制restore...

  • css圆角框学习

    宽度固定高度自适应 高度宽度自适应

  • CollectionView总结 OC 2020

    UICollectionViewCell 实现UICollectionViewCell自适应文字宽度https:/...

  • 元素自适应内容宽度

    需求: 要求元素的宽度能够自适应内容的宽度针对的是非内联元素,内联元素会自动的实现对内容宽度的自适应 这里是子元...

  • 关于加载js页面

    图片自适应宽度(webView加载的时候) 设置字体加载图片(label或者textView加载的时候)

  • imageView 指定比例适配

    在ConstraintLayout 布局中,imageView 宽度等屏幕宽度,高度自适应,

网友评论

      本文标题:Android 实现textview在一定宽度内自适应宽度

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