ConstraintLayout,横向排列左右紧靠,左边长度自适应但不会顶掉右边

<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context=".MarketActivity">

    <ImageView
            android:id="@+id/iv"
            android:layout_width="30dp"
            android:layout_height="30dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:background="@mipmap/add_more"/>

      <TextView
            android:id="@+id/tv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="上的根据日本数量价格对比fvgjgjtrof见佛国今天如果不的结果i如果将"
            android:lines="1"
            android:ellipsize="end"
            app:layout_constraintHorizontal_bias="0"
            app:layout_constraintHorizontal_chainStyle="packed"
            app:layout_constraintLeft_toRightOf="@id/iv"
            app:layout_constraintRight_toLeftOf="@+id/iv2"
            app:layout_constraintTop_toTopOf="@id/iv"
            app:layout_constraintBottom_toBottomOf="@id/iv"
            app:layout_constraintWidth_default="wrap" />

       <ImageView
            android:id="@+id/iv2"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="10dp"
            app:layout_constraintLeft_toRightOf="@id/tv"
            app:layout_constraintTop_toTopOf="@id/tv"
            app:layout_constraintBottom_toBottomOf="@id/tv"
            app:layout_constraintRight_toRightOf="parent"
            android:background="@mipmap/message"/>


 </androidx.constraintlayout.widget.ConstraintLayout>

文本字数过长时效果图如下:

 文本字数小于手机屏幕宽度效果图如下:

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现自适应长度横向滚动公告,可以使用CSS3的flex布局和marquee标签。具体步骤如下: 1. 使用一个div元素作为容器,设置宽度为100%、高度为固定值,并且设置overflow属性为hidden,使内容超过div大时被隐藏。 2. 在div容器内部创建一个ul元素,并使用CSS3的flex布局,设置flex-wrap属性为nowrap,使ul元素内部的li元素无法换行。 3. 对ul元素设置white-space属性为nowrap,使ul元素内部的文本不换行。 4. 对li元素设置display:inline-block,使li元素能够在一行内显示。 5. 使用marquee标签来实现横向滚动的效果,并将marquee标签内部的内容设置为ul元素。 6. 通过CSS3的media query来实现不同屏幕尺寸下的适配。 下面是示例代码: HTML代码: ``` <div class="notice-container"> <marquee behavior="scroll" direction="left"> <ul class="notice-list"> <li>第一条公告信息</li> <li>第二条公告信息</li> <li>第三条公告信息</li> <li>第四条公告信息</li> <li>第五条公告信息</li> <li>第六条公告信息</li> <li>第七条公告信息</li> </ul> </marquee> </div> ``` CSS代码: ``` .notice-container { width: 100%; height: 50px; overflow: hidden; } .notice-list { display: flex; flex-wrap: nowrap; white-space: nowrap; } .notice-list > li { display: inline-block; } @media screen and (max-width: 768px) { .notice-list > li { font-size: 12px; } } @media screen and (min-width: 768px) and (max-width: 992px) { .notice-list > li { font-size: 14px; } } @media screen and (min-width: 992px) { .notice-list > li { font-size: 16px; } } ``` 通过上述步骤,就可以实现一个自适应长度横向滚动公告了。可以根据需要调整容器的高度、文本的字体大小、marquee标签的滚动速度等参数来适应不同的场景。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值