加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 在xCode中包装内容UILabel

发布时间:2020-12-14 17:26:30 所属栏目:百科 来源:网络整理
导读:我正在尝试制作一个在同一行上有两个UILabel的单元格. 像这样: User Name: blablabla 用户名是第一个UILabel,blablabla是第二个UILabel. 我希望第一个UILabel包装内容,第二个将其内容扩展到超级视图的尾随. 我试图围绕StackOverflow寻找我的问题的答案,但我
我正在尝试制作一个在同一行上有两个UILabel的单元格.
像这样:

User Name: blablabla

用户名是第一个UILabel,blablabla是第二个UILabel.

我希望第一个UILabel包装内容,第二个将其内容扩展到超级视图的尾随.

我试图围绕StackOverflow寻找我的问题的答案,但我找不到一个.有人知道我怎么能实现这一目标?

我想要这样的东西:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/first_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="User Name:"/>

    <TextView
        android:id="@+id/second_label"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="bla bla bla"/>

</LinearLayout>

或者像这样

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/first_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="User Name:"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <TextView
        android:id="@+id/second_label"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="bla bla bla"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toRightOf="@id/first_label"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>

解决方法

尝试更改内容压缩阻力优先级

看看这些快照:

具有默认内容压缩阻力优先级的标签

enter image description here

我改变了标签blablabla blablabla的内容抗压性优先级,从750到749.

结果是:

enter image description here

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读