Android布局中的空格以及占一个汉字宽度的空格,实现不同汉字字数对齐
前言
在Android布局中进行使用到空格,以便实现文字的对齐。那么在Android中如何表示一个空格呢?
- 空格: (普通的英文半角空格但不换行)
- 窄空格:
- (中文全角空格 (一个中文宽度))
- (半个中文宽度,但两个空格比一个中文略大)
- (一个中文宽度,但用起来会比中文字宽一点点)
- \u3000\u3000(首行缩进)
- \u3000(全角空格(中文符号))
- \u0020(半角空格(英文符号))
- …(省略号)
所以如果想要实现文字对齐,那么可以考虑下面的方案:
方案一:一个汉字宽度的空格:
方案二:一个汉字宽度的空格: 【用两个空格( )占一个汉字的宽度时,两个空格比一个汉字略窄,三个空格( )比一个汉字略宽】;使用 ‒时候部分机型转译后不是空格,而是“-”;而且在不同机型有不同表现。
方案三:一个汉字宽度的空格: 【比一个中文略大】
方案四:一个汉字宽度的空格: 【比一个中文略大】
注意:以上方案是直接写在布局文件中,如果是写在strings.xml文件中,则需要使用\u3000、\u0020这一类的,比如:
<string name="info_pwd">\u3000\u3000密码:</string>
然后在布局文件中通过下面的方式引用
android:text="@string/info_pwd"
至于,为什么在strings.xml文件中使用\u3000代替 ,则是因为Android Studio3.2 + Gradle Plugn 3.2.0 + Gradle4.6环境下, 、 都不起作用了。
效果图
效果0:未作处理的效果
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户名:"
android:background="#54ff0000"
android:padding="8dp"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密码:"
android:background="#5400ff00"
android:padding="8dp"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="电子邮箱:"
android:background="#540000ff"
android:padding="8dp"/>
</LinearLayout>
效果一、使用
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 用户名:"
android:background="#54ff0000"
android:padding="8dp"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 密码:"
android:background="#5400ff00"
android:padding="8dp"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="电子邮箱:"
android:background="#540000ff"
android:padding="8dp"/>
</LinearLayout>
效果二、使用
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 用户名:"
android:background="#54ff0000"
android:padding="8dp"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 密码:"
android:background="#5400ff00"
android:padding="8dp"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="电子邮箱:"
android:background="#540000ff"
android:padding="8dp"/>
</LinearLayout>
效果三、使用
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 用户名:"
android:background="#54ff0000"
android:padding="8dp"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 密码:"
android:background="#5400ff00"
android:padding="8dp"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="电子邮箱:"
android:background="#540000ff"
android:padding="8dp"/>
</LinearLayout>
效果四、使用
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 用户名:"
android:background="#54ff0000"
android:padding="8dp"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 密码:"
android:background="#5400ff00"
android:padding="8dp"/> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="电子邮箱:"
android:background="#540000ff"
android:padding="8dp"/>
</LinearLayout>
参考资料:
Android开发中Html.fromHtml(String source)方法过时的替代方法
三种空格unicode(\u00A0,\u0020,\u3000)表示的区别
Android布局中的空格以及占一个汉字宽度的空格,实现不同汉字字数对齐的更多相关文章
- Android布局中的空格以及占一个汉字宽度的空格的实现
在Android布局中进行使用到空格,以便实现文字的对齐.那么在Android中如何表示一个空格呢? 空格: 窄空格: 一个汉字宽度的空格: [用两个空格( )占一个汉字的宽度时,两个空格比 ...
- android布局中使用include及需注意点
在android布局中,使用include,将另一个xml文件引入,可作为布局的一部分,但在使用include时,需注意以下问题: 一.使用include引入 如现有标题栏布局block_header ...
- android 布局中 layout_gravity、gravity、orientation、layout_weight
线性布局中,有 4 个及其重要的参数,直接决定元素的布局和位置,这四个参数是 android:layout_gravity ( 是本元素相对于父元素的重力方向 ) android:gravity (是 ...
- Android布局中的layout_weight和weightSum属性的详解及使用
由于Android设备的尺寸大小不一,种类繁多,当我们在开发应用的时候就要考虑屏幕的适配型了,尽可能让我们的应用适用于主流机型的尺寸,这样我们的应用不会因为尺寸不同而不美观,解决屏幕适配问题的方法有很 ...
- android: android 布局中的weight 属性
android: weight是线性布局的特有属性,控件的宽度和高度的不同,也会存在差异. 示例1:将宽度设置为包裹类型wrap_content或0dp <?xml version=" ...
- 【转】在Android布局中使用include和merge标签
内容转自:http://fengweipeng1208.blog.163.com/blog/static/21277318020138229754135/ 在我们开发android布局时,经常会有很多 ...
- Android布局中涉及的一些属性
Android:gravity属性 线性布局常见的就是利用LinearLayout进行布局,其中有个比较重要的属性就是android:gravity,在官方文档中是这么描述这个属性的:指定一个元素怎么 ...
- Android布局中match_parent和fill_parent的差别
今天在做项目的一个新功能的时候,从网上查找资源,发现android2.2中出现的MATCH_PARENT感到不明确.过去仅仅有FILL_PARENT和WRAP_CONTENT那么match_paren ...
- android布局中显示隐藏动画
android 在布局中提供属性,能简单的加入动画效果,例如以下: <LinearLayout ... animateLayoutChanges="true" ... /&g ...
随机推荐
- 浅谈如何获取机器的memory和CPU信息
最近做了一个项目,需要获取机器的CPU和memory的使用情况.花了一些时间网上搜索了一下,自己也做了些测试.总结下来,基本上2种方式:一种是用WMI(2种),另一种是用Performance cou ...
- 移动端常见bug
meta基础知识 H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 <meta name="viewport" content="width=device-wid ...
- 《团队-爬取豆瓣top250-开发文档》
项目托管平台地址:https://github.com/gengwenhao/GetTop250.git 本项目能够爬取豆瓣电影TOP250并向用户展示电影的排名,分数等
- 构建器Constructor的返回值/构建器
构建器Constructor的返回值? 为什么会有这个问题? 在<Thinking in Java>中文Quanke翻译版本第四章初始化和清除,原书第五章Initialization&am ...
- 20155205 郝博雅 Exp7 网络欺诈防范
20155205 郝博雅 Exp7 网络欺诈防范 一.实践内容 (1)简单应用SET工具建立冒名网站 (1分) (2)ettercap DNS spoof (1分) (3)结合应用两种技术,用DNS ...
- pip3 install的时候报错timed out
问题: 执行pip install requests报错 Read timed out. 解决方法: 修改超时时间: pip --default-timeout=1000 install -U r ...
- 2018年2月19日我的java学习(——)
在学完了类和对象的时候,开始对面向对象的思想有了一点认识,不过也不是完全的理解了. 就现在的学习状态来说,是非常的不错的,但是在学习的内容来说,我学的好像只是跟随这 站长的思路而已,也许是经验不足吧. ...
- java(二)Web部分
2.1.1讲一下http get和post请求的区别? GET和POST请求都是http的请求方式,用户通过不同的http的请求方式完成对资源(url)的不同操作.GET,POST,PUT,DELET ...
- C# 自动程序 windows 无法启动 XXXX 服务 错误5 拒绝访问
遇到过两次 这样的问题了,所以记录一下 原因可能是服务所在文件的目录权限不够 解决方法: 1是查看服务对应的程序所在的目录 2是设置目录的安全权限 右击–属性–安全–添加相应的帐号,给予除完全控制外的 ...
- 新FSM的一些思路
好久之前写过一篇关于状态机的小例子,可以看这里http://www.cnblogs.com/mawanli/p/5966080.html,这篇博客首先感谢需要感谢当时看到凉鞋的笔记博客, 凉鞋的博客地 ...