一、TextView

Button是继承TextView,TextView有的,同样Button也有以下特点:

1、空格占位法

== 普通的英文半角空格

  == ==   (普通的英文半角空格但不换行)

  == 中文全角空格 (一个中文宽度)

== == en空格 (半个中文宽度)

== == em空格 (一个中文宽度)

== 四分之一em空格 (四分之一中文宽度)

举个空格例子:

  • 在布局中
<LinearLayout    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="@color/white"    android:orientation="vertical">    <TextView      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:text="姓 名" />    <TextView      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:text="身份证" />LinearLayout>
  • 在代码中
setText("姓` `名");setText("身份证");

2、首行缩进

  • 在布局中,在文字的前面加入”\u3000\u3000”

  • 在代码中,使用setText(“\u3000\u3000”+xxxxx);

3、设置文字 + 图片

这里举文字左边有图片的例子(其他三个方向也同理):

  • 在布局中
android:drawableLeft="@mipmap/icon_praise"android:drawablePadding="5dip"
  • 在代码中
TextView tv = ...;tv.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.icon_praise, 0, 0, 0);tv.setCompoundDrawablePadding(5);

4、设置字形

android:textStyle:设置字形[bold(粗体) 0, italic(斜体) 1, bolditalic(又粗又斜) 2] 可以设置一个或多个,用“|”隔开

这里举例设置粗体:

  • 在布局中
 android:textStyle="bold"
  • 在代码中
TextView tv = ...;TextPaint tp = tv.getPaint();tp.setFakeBoldText(true);

5、使用&符号

提示unescaped & or nonterminated character/entity reference,

情景:在使用databinding布局中用到表达式时出现的问题,同样其他也适用。

原因:IDEA将“&”当成了特殊符号。

解决方法:将“&”改写为 &

二、Button

1、设置padding无效

设置水平padding的话,minWidth=0才有效
设置垂直padding的话,minHeight=0才有效

如下代码:

android:minHeight="0dp"android:minWidth="0dp"

后续更新。。。

更多相关文章

  1. 使用ViewPager实现android软件使用向导的功能
  2. Android(安卓)TextView学习
  3. Android(安卓)Transition——提高一点点篇
  4. Android的Toolbar(含溢出菜单设置[弹出菜单的使用])的使用PopMen
  5. SystemProperties與Settings.System
  6. Notification的功能与用法
  7. Android之TextView动态设置图片
  8. Android切换语言不重启应用的解决方案
  9. android 开发实现悬浮窗体

随机推荐

  1. Android 开发笔记 —— AndroidStudio 中
  2. android的一些开源项目
  3. Android(安卓)开发绕不过的坑:你的 Bitmap
  4. Android(安卓)实现微信聊天一样的布局
  5. 为数不多的人知道的AndroidStudio快捷键(
  6. Android 轻松实现语音识别
  7. 高级控件之网格视图(GridView)
  8. android studio 4.0. gradle 4.0. tinker
  9. Android(安卓)- ToDoList(fragment) 详解
  10. Android中的ellipsize