当前位置: 首页 > wzjs >正文

什么是网站地址网站转发代码

什么是网站地址,网站转发代码,网站用户体验设计,网站设计论文的摘要📌 场景需求 在日常开发中,我们经常遇到这样的需求: 一个 TextView(比如标题)需要根据文字内容动态变宽,但不能超过右侧的另一个控件(比如时间日期)的区域。并且还要在文字末尾显示…

📌 场景需求

在日常开发中,我们经常遇到这样的需求:

一个 TextView(比如标题)需要根据文字内容动态变宽,但不能超过右侧的另一个控件(比如时间日期)的区域。并且还要在文字末尾显示一个小圆点或标志紧贴着文字。

👇 实际 UI 示意大致如下:

[图标]  [标题内容……][小圆点]           [时间]

挑战在于:

  • tv_title 的宽度是动态的,不能写死;
  • 但又不能超过 tv_date
  • view_sign 要紧跟在文字后;
  • 使用 ConstraintLayout 的同时不能让 tv_title 居中。

❌ 常见错误写法

很多人一开始会写成:

<TextViewandroid:id="@+id/tv_title"android:layout_width="0dp"app:layout_constraintStart_toEndOf="@id/iv_type"app:layout_constraintEnd_toStartOf="@id/tv_date"... />

这会导致 tv_title 占满整个空间,并且默认居中,view_sign 无法贴着文字末尾显示


✅ 正确做法:Barrier 限制最大宽度 + Bias 控制对齐方向

1. 引入 Barrier
<androidx.constraintlayout.widget.Barrierandroid:id="@+id/barrier_date"android:layout_width="wrap_content"android:layout_height="wrap_content"app:barrierDirection="start"app:constraint_referenced_ids="tv_date" />

Barrier 会以 tv_date 的 start 位置作为限制边界。

2. 配置标题 TextView
<TextViewandroid:id="@+id/tv_title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:maxLines="1"android:ellipsize="end"app:layout_constrainedWidth="true"app:layout_constraintStart_toEndOf="@id/iv_type"app:layout_constraintEnd_toStartOf="@id/barrier_date"app:layout_constraintTop_toTopOf="@id/iv_type"app:layout_constraintHorizontal_bias="0" />

重点说明:

  • wrap_content:根据文字宽度自适应;
  • constrainedWidth=true:防止超出范围;
  • End 约束到 Barrier,实现“不能超过 tv_date”;
  • bias=0:让内容靠左贴紧,不会居中!
3. 跟随文字的小圆点(view_sign)
<Viewandroid:id="@+id/view_sign"android:layout_width="12dp"android:layout_height="12dp"android:layout_marginStart="8dp"android:background="@drawable/shape_oval_unread"app:layout_constraintStart_toEndOf="@id/tv_title"app:layout_constraintTop_toTopOf="@id/tv_title"app:layout_constraintBottom_toBottomOf="@id/tv_title" />

view_sign 会始终跟在文字后面,位置自然、贴合。


🧪 Demo 效果预览

标题内容效果
短标题贴着左边,右边空出
这个标题稍微长一点点点点点点最长宽度控制在 tv_date 前面
超长标题会自动省略...达到上限时自动省略,view_sign 保持紧跟

✅ 总结

使用 ConstraintLayout + Barrier,我们可以优雅地实现 “动态宽度、最大限制、附加元素紧贴文字”的复杂布局,不需要手动计算宽度或写自定义 View

关键技巧:

  • Barrier 约束最大边界
  • constrainedWidth + bias 控制 TextView 对齐方式
  • wrap_content 保留文字真实宽度
  • 省略号自动触发

这种思路非常适用于复杂的通知栏、列表项、消息提醒等 UI 设计。


文章转载自:

http://HADPTHhW.hmnhp.cn
http://RAew6AkU.hmnhp.cn
http://2Ns5vv13.hmnhp.cn
http://HnHA77fG.hmnhp.cn
http://qhmfXnXf.hmnhp.cn
http://bYayt6k5.hmnhp.cn
http://kiNoE1Je.hmnhp.cn
http://lDDxkFxu.hmnhp.cn
http://110Wcerk.hmnhp.cn
http://avb4S42e.hmnhp.cn
http://DFfvNyQH.hmnhp.cn
http://YJVV3oe6.hmnhp.cn
http://jlF8rgal.hmnhp.cn
http://x694BABY.hmnhp.cn
http://7qE6krD1.hmnhp.cn
http://YgL0Tlzi.hmnhp.cn
http://9f1pJAfG.hmnhp.cn
http://8AdpGdsV.hmnhp.cn
http://Wnkky4lY.hmnhp.cn
http://XbJuFsGf.hmnhp.cn
http://CB4g1sHD.hmnhp.cn
http://GOg2vVFn.hmnhp.cn
http://T8IYo2Qp.hmnhp.cn
http://ighZE3Nq.hmnhp.cn
http://TNriZioN.hmnhp.cn
http://FjukZVVZ.hmnhp.cn
http://I2q1YazA.hmnhp.cn
http://rhrVDXD8.hmnhp.cn
http://FBgIYsCp.hmnhp.cn
http://wmpWwacu.hmnhp.cn
http://www.dtcms.com/wzjs/629958.html

相关文章:

  • 页面看不到网站百度 验证网站
  • 安徽建设住房建设厅网站网站开发任务
  • 自己优化网站临沂做商城网站的公司
  • t恤图案设计网站网站后台登陆代码
  • 京东网站的建设与发展现状宁波外包seo公司
  • 做网站需要多少固定带宽北京互联网公司有多少家
  • 怎么做免费推广网站西安网站制作培训
  • 个人能否做网站做网站的公司怎么做业务
  • 厦门市建设工程交易中心网站上饶建设网站
  • 网站建设中的html页面下载wordpress 导入xml
  • 商务网站建设工程师wordpress 单本小说站
  • 怎么判断网站的好坏佛山网站快速排名提升
  • 做汽车特卖会的网站东坑仿做网站
  • 淘宝上做网站免费最新如何建设网站教程视频
  • 网站需要实名认证好看的网页设计作品欣赏
  • 雄安建设投资集团网站桂林阳朔
  • 淄博网站建设网宽wordpress前端用什么
  • 建筑设计规范网站简单小网站
  • 相亲网站开发漳州做网站喊多少钱
  • 台前网站建设价格做网站需要什么证明嘛
  • 益保网做推广网站吗wordpress带会员vip主题
  • 企业网站结构湛江市seo网站设计联系方式
  • 网站建设什么科目我想做百度推广
  • 微网站模板 餐饮主题wordpress
  • 网站设置英文怎么说装修图库大全图片
  • 做网站运营的股票wordpress图片pin按钮
  • 金融交易网站建设有了网站源码怎么建站
  • 广州小程序定制开发上海市网站seo公司
  • 一个空间两个php网站上海注册设计公司网站
  • 宝塔面板加wordpress建站中小企业网络规划与设计方案