1、指定TextView一行显示几个字符,多余的省略号
android:singleLine="true"
android:ellipsize="end"
android:maxEms="4"
2、透明度转换
100% —FF–> ,95% — F2–> ,90% — E6–> ,85% — D9–> ,80% — CC–> ,75% — BF–> ,70% — B3–>,65% — A6–> ,60% — 99–> ,55% — 8C–> ,50% — 80–> ,45% — 73–> ,40% — 66–> ,35% — 59–> ,30% — 4D–> ,25% — 40–> ,20% — 33–> ,15% — 26–> ,10% — 1A–> ,5% — 0D–> ,0% — 00–>
3、shape写背景selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="#FFFFFF" />
</shape>
</item>
<item android:top="@dimen/y63"
android:bottom="@dimen/y17"
android:left="@dimen/x88"
android:right="@dimen/x88">
<shape android:shape="rectangle">
<solid android:color="#00a65f" />
<size android:height="@dimen/y4" android:width="@dimen/x40"/>
</shape>
</item>
</layer-list>
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff" />
</shape>
</item>
</selector>
4、指定TextView显示2行,多余的省略号
android:lines="2"
android:ellipsize="end"
5、ScrollView中嵌套RecyclerView显示不全
val layoutManager: LinearLayoutManager = object : LinearLayoutManager(holder.getContext()) {
override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams {
return RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT)
}
}
layoutManager.orientation = LinearLayoutManager.VERTICAL
re.layoutManager = layoutManager
6、TextView跑马灯
重写TextView的isFocused方法返回true
xml
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
7、TextView内容显示不全可以上下滑动
xml
android:scrollbars="vertical"
code
tvContent.movementMethod = ScrollingMovementMethod.getInstance()
8、TextView自动识别邮箱、电话、链接,点击可跳转
android:autoLink="email|phone|web"
9、TextView画虚线
需要在TextView的xml中添加,设置背景使用shape.xml
android:layerType="software"
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke
android:dashGap="@dimen/x6"
android:dashWidth="@dimen/x6"
android:width="@dimen/x2"
android:color="#D8D8D8" />
<!-- 虚线的高度 -->
<size android:height="@dimen/y2" />
</shape>
10、TextView去掉默认的边上空白间隙
android:includeFontPadding="false"