直播系统平台搭建,主播个性标签显示在id后面

直播系统平台搭建,主播个性标签显示在id后面实现的相关代码

具体实现

1.1文字限制一行时,标签在文字后面

文字较少时就像第一行这样,文字较多显示不下时就像二三行那样省略。

实现方法一,使用线性布局实现

 

1
<LinearLayout<br>            android:layout_width="wrap_content"<br>            android:layout_height="wrap_content"<br>            android:orientation="horizontal"><br>            <TextView<br>                android:layout_width="0dp"<br>                android:layout_height="wrap_content"<br>                android:layout_weight="1"<br>                android:text="不宽度,不确定字数"<br>                android:singleLine="true"<br>                /><br>            <TextView<br>                android:layout_width="wrap_content"<br>                android:layout_height="wrap_content"<br>                android:text="跟随标签"<br>                android:background="@color/yellow_FF9B52"/><br>            <TextView<br>                android:layout_width="wrap_content"<br>                android:layout_height="wrap_content"<br>                android:text="跟随标签2"<br>                android:background="@color/blue_74D3FF"/><br>        </LinearLayout>

​实现方法二,使用约束布局实现

 

1
<androidx.constraintlayout.widget.ConstraintLayout<br>            android:layout_width="match_parent"<br>            android:layout_height="wrap_content"><br>            <TextView<br>                android:id="@+id/refund_name"<br>                android:layout_width="wrap_content"<br>                android:layout_height="wrap_content"<br>                android:singleLine="true"<br>                android:text="长数据长数据长数据长数据长数据长数据长数据长数据长数据"<br>                app:layout_constrainedWidth="true"<br>                app:layout_constraintBottom_toBottomOf="parent"<br>                app:layout_constraintHorizontal_bias="0"<br>                app:layout_constraintHorizontal_chainStyle="packed"<br>                app:layout_constraintLeft_toLeftOf="parent"<br>                app:layout_constraintRight_toLeftOf="@id/refund_mark_num"<br>                app:layout_constraintTop_toTopOf="parent" /><br>            <TextView<br>                android:id="@+id/refund_mark_num"<br>                android:layout_width="wrap_content"<br>                android:layout_height="wrap_content"<br>                android:background="@color/yellow_FF9B52"<br>                android:text="跟随标签"<br>                android:gravity="center"<br>                app:layout_constrainedWidth="true"<br>                app:layout_constraintLeft_toRightOf="@+id/refund_name"<br>                app:layout_constraintRight_toRightOf="parent"<br>                app:layout_constraintTop_toTopOf="parent" /><br>        </androidx.constraintlayout.widget.ConstraintLayout>

1.2标签在文字前面时

实现思路和上面标签在文字后面一样。第一行的标签是一个控件,标签后面的文字是一个单独的 TextView,第二行也是一个单独的 TextView。如果想限制文字行数,直接对第二行的 TextView 限制就行。

xml 布局:

 

1
 <!--        前面跟随标签--><br>        <TextView<br>            android:layout_width="wrap_content"<br>            android:layout_height="wrap_content"<br>            android:text="前面跟随标签"<br>            android:textColor="@color/white"<br>            android:background="@color/red"<br>            /><br>        <androidx.constraintlayout.widget.ConstraintLayout<br>            android:layout_width="match_parent"<br>            android:layout_height="wrap_content"<br>            android:layout_marginHorizontal="@dimen/m15"><br>            <TextView<br>                android:id="@+id/tv_rl_test_tagFront"<br>                android:layout_width="wrap_content"<br>                android:layout_height="wrap_content"<br>                android:text="标签"<br>                android:background="@color/yellow_FF9B52"<br>                app:layout_constraintTop_toTopOf="parent"<br>                app:layout_constraintStart_toStartOf="parent"/><br>            <com.kiwilss.xview.widget.textview.AlignTextView<br>                android:id="@+id/tv_rl_test_frontOne"<br>                android:layout_width="0dp"<br>                android:layout_height="wrap_content"<br>                android:text="任意显示一行任意显示一行任意显示一行任意显示一行任意显示一行"<br>                app:layout_constraintTop_toTopOf="parent"<br>                app:layout_constraintStart_toEndOf="@+id/tv_rl_test_tagFront"<br>                android:maxLines="1"<br>                /><br>            <com.kiwilss.xview.widget.textview.AlignTextView<br>                android:id="@+id/tv_rl_test_frontTwo"<br>                android:layout_width="match_parent"<br>                android:layout_height="wrap_content"<br>                android:text="任意显示一行任意显示一行任意显示一行任意显示一行任意显示一行"<br>                app:layout_constraintTop_toBottomOf="@+id/tv_rl_test_tagFront"/><br>        </androidx.constraintlayout.widget.ConstraintLayout>

activity 部分:

 

1
  //前面加标签<br>        TextView tvFront = (TextView) findViewById(R.id.tv_rl_test_tagFront);<br>        TextView tvFrontOne =  findViewById(R.id.tv_rl_test_frontOne);<br>        TextView tvFrontTwo =  findViewById(R.id.tv_rl_test_frontTwo);<br>        tvFrontOne.setText(tagSrc);<br>        //获取tvFrontOne显示的内容<br>        tvFrontOne.post(new Runnable() {<br>            @Override<br>            public void run() {<br>                //获取第一行显示的内容<br>                String lineContent = Utils.INSTANCE.getTextLineContent(tvFrontOne, 0, tagSrc);<br>                if (TextUtils.equals(lineContent,tagSrc)){<br>                    //一行可以完整显示<br>                    tvFrontTwo.setVisibility(View.GONE);<br>                }else {<br>                    //需要多行才能显示<br>                    tvFrontTwo.setVisibility(View.VISIBLE);<br>                    String nextContent = tagSrc.substring(lineContent.length(), tagSrc.length());<br>                    tvFrontTwo.setText(nextContent);<br>                }<br>            }<br>        });

 

以上就是直播系统平台搭建,主播个性标签显示在id后面实现的相关代码, 更多内容欢迎关注之后的文章

 

posted @   云豹科技-苏凌霄  阅读(289)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示