Android源码分析(十二)-----Android源码中如何自定义TextView实现滚动效果
一:如何自定义TextView实现滚动效果
- 继承TextView基类
- 重写构造方法
- 修改
isFocused()
方法,获取焦点。
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.utils;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
public class FocusedTextView extends TextView {
public FocusedTextView(Context context) {
super(context);
}
public FocusedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FocusedTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public boolean isFocused() {
return true;
}
}
二:布局xml文件写法
主要设置如下两项:
android:singleLine="true"
单行显示
android:ellipsize="marquee"
滚动
<?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="wrap_content"
android:focusable="true"
android:orientation="vertical" >
<!--FocusedTextView的全路径名称,其他选项设置和TextView一样-->
<com.android.settings.utils.FocusedTextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:paddingLeft="@dimen/item_padding_x"
android:singleLine="true"
android:ellipsize="marquee"
android:textColor="@drawable/app_text_color"
android:textSize="@dimen/item_textsize" />
<com.android.settings.utils.FocusedTextView
android:id="@+id/summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:paddingLeft="@dimen/item_padding_x"
android:singleLine="true"
android:ellipsize="marquee"
android:text="Summary"
android:textColor="@drawable/app_text_color"
android:textSize="@dimen/item_textsize" />
</LinearLayout>
三:总结
- 继承基类TextView
- 修改
isFocused()
方法 - 设置TextView属性
喜欢源码分析系列可参考其他文章:
Android源码分析(一)-----如何快速掌握Android编译文件
Android源码分析(二)-----如何编译修改后的framework资源文件
Android源码分析(三)-----系统框架设计思想
Android源码分析(四)-----Android源码编译及刷机步骤
Android源码分析(五)-----如何从架构师的角度去设计Framework框架
Android源码分析(十二)-----Android源码中如何自定义TextView实现滚动效果的更多相关文章
- ABP源码分析十二:本地化
本文逐个分析ABP中涉及到locaization的接口和类,以及相互之间的关系.本地化主要涉及两个方面:一个是语言(Language)的管理,这部分相对简单.另一个是语言对应得本地化资源(Locali ...
- [Abp 源码分析]十二、多租户体系与权限验证
0.简介 承接上篇文章我们会在这篇文章详细解说一下 Abp 是如何结合 IPermissionChecker 与 IFeatureChecker 来实现一个完整的多租户系统的权限校验的. 1.多租户的 ...
- jQuery 源码分析(十二) 数据操作模块 html特性 详解
jQuery的属性操作模块总共有4个部分,本篇说一下第1个部分:HTML特性部分,html特性部分是对原生方法getAttribute()和setAttribute()的封装,用于修改DOM元素的特性 ...
- Vue.js 源码分析(十二) 基础篇 组件详解
组件是可复用的Vue实例,一个组件本质上是一个拥有预定义选项的一个Vue实例,组件和组件之间通过一些属性进行联系. 组件有两种注册方式,分别是全局注册和局部注册,前者通过Vue.component() ...
- Heritrix源码分析(十二) Heritrix的控制中心(大脑)CrawlController(一)(转)
本博客属原创文章,欢迎转载!转载请务必注明出处:http://guoyunsky.iteye.com/blog/650694 本博客已迁移到本人独立博客: http://www.yun5u.com/ ...
- MyBatis框架的使用及源码分析(十二) ParameterHandler
在StatementHandler使用prepare()方法后,接下来就是使用ParameterHandler来设置参数,让我们看看它的定义: package org.apache.ibatis.ex ...
- Alink漫谈(二十二) :源码分析之聚类评估
Alink漫谈(二十二) :源码分析之聚类评估 目录 Alink漫谈(二十二) :源码分析之聚类评估 0x00 摘要 0x01 背景概念 1.1 什么是聚类 1.2 聚类分析的方法 1.3 聚类评估 ...
- 一个普通的 Zepto 源码分析(二) - ajax 模块
一个普通的 Zepto 源码分析(二) - ajax 模块 普通的路人,普通地瞧.分析时使用的是目前最新 1.2.0 版本. Zepto 可以由许多模块组成,默认包含的模块有 zepto 核心模块,以 ...
- Zepto源码分析(二)奇淫技巧总结
Zepto源码分析(一)核心代码分析 Zepto源码分析(二)奇淫技巧总结 目录 * 前言 * 短路操作符 * 参数重载(参数个数重载) * 参数重载(参数类型重载) * CSS操作 * 获取属性值的 ...
随机推荐
- 【2019.7.15 NOIP模拟赛 T2】与非树(nand)(树形DP)
树形\(DP\) 实际上,这道题应该不是很难. 我们设\(f_{x,i,j}\)表示在以\(x\)为根的子树内,原本应输出\(i\),结果输出了\(j\)的情况数. 转移时,为了方便,我们先考虑与,再 ...
- [LeetCode] 347. Top K Frequent Elements 前K个高频元素
Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [ ...
- [LeetCode] 90. Subsets II 子集合之二
Given a collection of integers that might contain duplicates, S, return all possible subsets. Note: ...
- oracle 错误 TNS-01190与oracle 登入没反应操作
1,问题描述 [oracle@node2 ~]$ lsnrctl stop LSNRCTL - Production on -MAY- :: Copyright (c) , , Oracle. All ...
- 关于App收集个人信息基本规范,这里公开征求你的意见!
关于App收集个人信息基本规范,这里公开征求你的意见! https://www.thepaper.cn/newsDetail_forward_4122573 以后国家开始规范App收集个信息基本规范, ...
- 论文阅读: Infrastructure-Based Calibration of a Multi-Camera Rig
Abstract 在线标定很重要. 但是目前的方法都计算量都很高. 我们的方案不需要标定板之类的东西. 我们的方案不需要假设相机有重合的FOV,也不需要任何的初始猜测. 当相机模组行驶穿过之前建过地图 ...
- Python【每日一问】38
问: 基础题: 设计一个经营杠杆系数函数DOL,它包含三个参数,S为营业收入,C为变动成本总额,F为固定成本的总额. 已知2018年的S为20,C为11,F为3,求2019年的经营杠杆系数. 提高题: ...
- Oracle体系结构学习笔记
Oracle体系结构由实例和一组数据文件组成,实例由SGA内存区,SGA意思是共享内存区,由share pool(共享池).data buffer(数据缓冲区).log buffer(日志缓冲区)组成 ...
- java.lang.IllegalStateException: Received message from unsupported version: [5.2.2] minimal compatible version is: [5.6.0]
启动elasticsearch-6.2.2-Windows服务时报错: java.lang.IllegalStateException: Received message from unsupport ...
- kvm虚拟机vnc配置
通过vnc方式访问虚拟主机上的KVM虚拟机 通过虚拟主机的IP地址与端口进行访问 1. 修改qemu.conf # vi /etc/libvirt/qemu.conf vnc_listen = &q ...