TextView把其它控件挤出屏幕的处理办法

news2024/10/11 18:38:42

1.如果TextView后面的控件是紧挨着TextView的,可以给TextView添加maxWidth限制其最大长度

上有问题的布局代码

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>

        <import type="android.text.TextUtils" />

        <variable
            name="appCardEntity"
            type="cn.com.westone.cxjr.cxsdk.model.AppCardEntity" />

        <variable
            name="adapter"
            type="cn.com.westone.cx.platform.fragment.sub.card.AppCardKeyDataType.AppCardKeyDataAdapter" />


    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/shape_search_bg"
        android:orientation="vertical"
        android:paddingHorizontal="16dp"
        android:paddingVertical="8dp">

        <LinearLayout
            android:id="@+id/ll_title"
            android:layout_width="match_parent"
            android:layout_height="32dp"
            android:gravity="center_vertical"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/iv_icon"
                android:layout_width="16dp"
                android:layout_height="16dp"
                android:padding="2dp"
                android:src="@drawable/ic_placeholder" />

            <com.westone.cx.commonsdk.uikit.scaleView.CXScaleTextView
                android:id="@+id/tv_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ellipsize="end"
                android:gravity="center_horizontal"
                android:maxLines="1"
                android:text="@{TextUtils.isEmpty(appCardEntity.cardTitle)?appCardEntity.appName:appCardEntity.cardTitle}"
                android:textColor="@color/cx_first_level_text_color"
                android:textSize="@dimen/store_font_12" />

            <ImageView
                android:layout_width="16dp"
                android:layout_height="16dp"
                android:background="@drawable/arrow_right_icon"
                android:padding="2dp" />
        </LinearLayout>

        <cn.com.westone.cx.platform.fragment.sub.component.NonScrollGridView
            android:id="@+id/gv_data"
            adapter="@{adapter}"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingVertical="16dp" />
    </LinearLayout>
</layout>

有问题时展示效果图

解决方案布局代码

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>

        <import type="android.text.TextUtils" />

        <variable
            name="appCardEntity"
            type="cn.com.westone.cxjr.cxsdk.model.AppCardEntity" />

        <variable
            name="adapter"
            type="cn.com.westone.cx.platform.fragment.sub.card.AppCardKeyDataType.AppCardKeyDataAdapter" />


    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/shape_search_bg"
        android:orientation="vertical"
        android:paddingHorizontal="16dp"
        android:paddingVertical="8dp">

        <LinearLayout
            android:id="@+id/ll_title"
            android:layout_width="match_parent"
            android:layout_height="32dp"
            android:gravity="center_vertical"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/iv_icon"
                android:layout_width="16dp"
                android:layout_height="16dp"
                android:padding="2dp"
                android:src="@drawable/ic_placeholder" />

            <com.westone.cx.commonsdk.uikit.scaleView.CXScaleTextView
                android:id="@+id/tv_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ellipsize="end"
                android:gravity="center_horizontal"
                android:maxWidth="200dp" //关键代码
                android:maxLines="1"
                android:text="@{TextUtils.isEmpty(appCardEntity.cardTitle)?appCardEntity.appName:appCardEntity.cardTitle}"
                android:textColor="@color/cx_first_level_text_color"
                android:textSize="@dimen/store_font_12" />

            <ImageView
                android:layout_width="16dp"
                android:layout_height="16dp"
                android:background="@drawable/arrow_right_icon"
                android:padding="2dp" />
        </LinearLayout>

        <cn.com.westone.cx.platform.fragment.sub.component.NonScrollGridView
            android:id="@+id/gv_data"
            adapter="@{adapter}"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingVertical="16dp" />
    </LinearLayout>
</layout>

解决完成后效果图

2.TextView控件和其它控件分别在两端展示时,TextView把其它控件挤出屏幕

上有问题的布局代码

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>

        <import type="android.view.View" />

        <variable
            name="appEntity"
            type="cn.com.westone.cx.platform.fragment.sub.card.AppCardListDataType.AppCardListDataItemEntity" />

        <variable
            name="adapter"
            type="cn.com.westone.cx.platform.fragment.sub.card.AppCardListDataType.AppCardListDataTypeAdapter" />

    </data>

    <RelativeLayout
        android:id="@+id/ll_item"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:minHeight="32dp">

        <TextView
            android:id="@+id/tv_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:ellipsize="end"
            android:gravity="left"
            android:maxLines="1"
            android:text="@{appEntity.text}"
            android:textColor="@color/cx_first_level_text_color"
            android:textSize="@dimen/store_font_12" />

        <TextView
            android:id="@+id/tv_time"
            android:layout_width="65dp"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:layout_alignParentRight="true"
            android:maxLines="1"
            android:text="@{appEntity.formatTime()}"
            android:textColor="@color/cx_second_level_text_color"
            android:textSize="@dimen/store_font_12"
            android:visibility="@{adapter.isHideTimeStamp?View.GONE:View.VISIBLE}" />
    </RelativeLayout>
</layout>

有问题时展示效果图

使用LinearLayout与weight属性解决方案布局代码

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>

        <import type="android.view.View" />

        <variable
            name="appEntity"
            type="cn.com.westone.cx.platform.fragment.sub.card.AppCardListDataType.AppCardListDataItemEntity" />

        <variable
            name="adapter"
            type="cn.com.westone.cx.platform.fragment.sub.card.AppCardListDataType.AppCardListDataTypeAdapter" />

    </data>

    <LinearLayout
        android:id="@+id/ll_item"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:minHeight="32dp">

        <TextView
            android:id="@+id/tv_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ellipsize="end"
            android:gravity="left"
            android:maxLines="1"
            android:text="@{appEntity.text}"
            android:textColor="@color/cx_first_level_text_color"
            android:textSize="@dimen/store_font_12" />

        <TextView
            android:id="@+id/tv_time"
            android:layout_width="65dp"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:maxLines="1"
            android:text="@{appEntity.formatTime()}"
            android:textColor="@color/cx_second_level_text_color"
            android:textSize="@dimen/store_font_12"
            android:visibility="@{adapter.isHideTimeStamp?View.GONE:View.VISIBLE}" />
    </LinearLayout>
</layout>

解决后效果图

原理是:LinearLayout里添加weight属性的控件会填满其它控件绘制完后剩余的全部空间。

仅以此记录一天的解决之路

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2205478.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

动态爬虫管理平台构建与实现(论文+源码)_kaic

摘 要 随着互联网的迅速发展&#xff0c;Web的信息量越来越大。人们往往通过搜索引擎去从互联网上搜索想要的信息&#xff0c;比如:百度&#xff0c;谷歌&#xff0c;搜狗等。这类搜索引擎称之为通用搜索引擎&#xff0c;其为所有的用户所需的内容&#xff0c;但目前互联网上的…

【网络原理】TCP协议提高效率的秘密-滑动窗口机制

&#x1f490;个人主页&#xff1a;初晴~ &#x1f4da;相关专栏&#xff1a;计算机网络那些事 如果我们严格依照“确认应答”机制&#xff0c;针对每一个发送的数据段&#xff0c;都需要一个ACK确认应答&#xff0c;当收到ACK应答报文后&#xff0c;才继续发下一个报文。这样…

2025届计算机保研经验贴(末九→浙江大学软件学院)

燕园再美美不过宁波港&#xff0c;没到过浙软的人不会明了 软微已死&#xff0c;浙软当立&#xff01; 文章目录 一、个人情况二、保研历程1、去年今日2、前期准备3、夏令营天大智算软件所西交软本校浙江大学软件学院 4、预推免 三、后记链式反应9.28下午冥场面9.29博弈 浙软当…

ClickHouse 24.9 版本发布说明

本文字数&#xff1a;7295&#xff1b;估计阅读时间&#xff1a;19 分钟 作者&#xff1a;ClickHouse Team 本文在公众号【ClickHouseInc】首发 又到新版本发布的时间了&#xff01; 发布概要 本次ClickHouse 24.9 版本包含了23个新功能&#x1f381;、14项性能优化&#x1f6f…

[已解决] HttpMessageNotReadableException: JSON parse error: Unexpected character

[已解决] HttpMessageNotReadableException: JSON parse error: Unexpected character 文章目录 写在前面问题描述报错原因分析&#xff1a; 解决思路解决办法1. 检查并修复客户端的 JSON 数据格式2. 确认请求头的 Content-Type 设置正确3. 捕获并处理 HttpMessageNotReadableE…

三层b+树估算存储多少行数据

文章目录 B树结构图示估算方法(这里要以聚簇索引来看) B树结构图示 估算方法(这里要以聚簇索引来看) 非叶子节点数* 每个叶子结点记录总数 假设mysql 数据页&#xff0c;16kb&#xff0c;刚好对应B树的一个节点 每个叶子结点记录数&#xff0c; 叶子结点存储的是对应的原始数据…

项目常用版本控制管理工具

不仅仅是代码管理工具 gitHubgitcodeSVN gitHub https://github.com/ github gitcode https://gitcode.com/ gitcode SVN 图片: 带尺寸的图片: 居中的图片: 居中并且带尺寸的图片:

git--git reset

HEAD 单独一个HEAD eg:git diff HEAD 表示当前结点。 HEAD~ HEAD~只处理当前分支。 注意&#xff1a;master分支的上一个结点是tmp分支的所在的结点fc11b74, 79f109e才是master的第二个父节点。 HEAD~ 当前结点的父节点。 HEAD~1 当前结点的父节点。 HEAD~n 当前结点索…

Python 工具库每日推荐 【easyocr】

文章目录 引言Python OCR 工具库的重要性今日推荐:EasyOCR 工具库主要功能:使用场景:安装与配置快速上手示例代码代码解释实际应用案例案例:多语言名片信息提取案例分析高级特性自定义模型训练处理倾斜文本扩展阅读与资源优缺点分析优点:缺点:总结【 已更新完 TypeScript…

Qt实现侧边栏功能

本文介绍Qt实现侧边栏功能。 采用Qt进行界面应用程序开发时&#xff0c;经常遇到侧边栏功能实现&#xff0c;采用侧边栏可以将一些暂时不用到的功能隐藏&#xff0c;使用的时候点击一下相应的按钮即可弹出&#xff08;动画方式&#xff09;功能菜单。减少主界面控件数量&#…

JS | JS中类的 prototype 属性和__proto__属性

大多数浏览器的 ES5 实现之中&#xff0c;每一个对象都有__proto__属性&#xff0c;指向对应的构造函数的prototype属性。Class 作为构造函数的语法糖&#xff0c;同时有prototype属性和__proto__属性&#xff0c;因此同时存在两条继承链。 构造函数的子类有prototype属性。‌ …

搭建知识库:助力大健康零售电商的快速发展

一、大健康零售电商行业的快速发展及其对知识库的需求 随着互联网技术的飞速发展和人们对健康意识的显著提升&#xff0c;大健康零售电商行业迎来了前所未有的发展机遇。这一行业不仅涵盖了传统零售业的商品销售&#xff0c;还融入了健康管理、健康咨询、健康数据分析等多元化…

『网络游戏』数据库表格转储【25】

避免勿删数据库表格&#xff0c;可以将表格存储 放到桌面即可 现在将表格删除后点击 浏览桌面表格保存即可 修改客户端脚本&#xff1a;NetSvc.cs 目的是在数据库更新异常时弹出提示以便修改 本章结束

使用 Helsinki-NLP 中英文翻译本地部署 - python 实现

通过 Helsinki-NLP 本地部署中英文翻译功能。该开源模型性价比相对高&#xff0c;资源占用少&#xff0c;对于翻译要求不高的应用场景可以使用&#xff0c;比如单词&#xff0c;简单句式的中英文翻译。 该示例使用的模型下载地址&#xff1a;【免费】Helsinki-NLP中英文翻译本…

Pura 70系列和Pocket 2已支持升级尝鲜鸿蒙NEXT,报名教程在这里

相信不少关注鸿蒙 NEXT 的人都知道&#xff0c;10月8日起&#xff0c;华为开启了鸿蒙 NEXT 系统的公测&#xff0c;但有不少人不知道的是&#xff0c;除了公测的 Mate 60 和 Mate X5 两个系列的机型&#xff0c;还有两个系列的手机其实也可以提前升级体验鸿蒙 NEXT 系统。 Pur…

随时随地一键开播的云微客实景直播神器,你想要吗?

AI实景直播系统正在以自动化、智能化的特性&#xff0c;逐渐成为直播行业的新宠。在众人频繁使用手机的时代背景下&#xff0c;直播已经成为了大多数人娱乐的方式之一&#xff0c;然而传统的直播方式不仅操作繁琐而且人员成本也高&#xff1b;现在云微客实景直播不仅可以告别人…

在工业现场,数据采集相关的对象一般有哪些类型?

在工业现场&#xff0c;数据采集相关的对象一般有以下类型&#xff1a;一、设备运行参数类1.温度 —描述&#xff1a;反映设备的发热情况、工作环境温度等&#xff0c;对于一些对温度敏感的设备&#xff08;如电子设备、精密机械等&#xff09;至关重要。 —举例&#xff1a;在…

企业注册资金如何实缴?步骤与方式详解

在企业的发展过程中&#xff0c;注册资金实缴是一个重要的环节。它不仅体现了企业的实力和信誉&#xff0c;也为企业的经营活动提供了坚实的资金保障。那么&#xff0c;在 2024 年&#xff0c;企业注册资金实缴的步骤和方式有哪些呢&#xff1f; 一、企业注册资金实缴步骤 1、确…

[C语言]结构体

1.什么是结构体 结构是多种类型的数据的集合。。且每个结构成员都有名字&#xff0c;因此当使用特定的成员时需要指明结构体成员的名字。 2.结构体的声明 以学生的数据为例&#xff1a; struct student //student结构名{char name; //name结构体成员名int height;…

传知代码-自动车牌识别检测系统(论文复现)

代码以及视频讲解 本文所涉及所有资源均在传知代码平台可获取 YOLO V8实现多种车牌检测识别&#xff01; 一、概述 使用yolov8进行车牌检测&#xff08;训练测试演示部署&#xff09; 二、支持类型 我们的车牌识别检测系统支持多种类型的车牌 具体支持类型如下&#xff1a…