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操作 * 获取属性值的 ...
随机推荐
- 201871010134-周英杰《面向对象程序设计(java)》第十三周学习总结
201871010134-周英杰<面向对象程序设计(java)>第十三周学习总结 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ ...
- 201871020225-牟星源《面向对象程序设计(java)》第6-7周学习总结
201871020225-牟星源<面向对象程序设计(java)>第6-7周学习总结 博文正文: 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu- ...
- selenium 2定位方式实例
#########百度输入框的定位方式########## #通过id方式定位 browser.find_element_by_id("kw").send_keys("s ...
- Git命令行操作(三)
1. 本地库初始化 进入指定目录,如:D:\gitSpace\OA 右键-->Git Bash Here,执行命令: git init 效果如下: #查看.git目录 ls -la # 进入.g ...
- zz神经网络模型量化方法简介
神经网络模型量化方法简介 https://chenrudan.github.io/blog/2018/10/02/networkquantization.html 2018-10-02 本文主要梳理了 ...
- JDOJ 1139 水仙花数
JDOJ 1139: 水仙花数 https://neooj.com/oldoj/problem.php?id=1139 Description 打印出所有"水仙花数",所谓&quo ...
- apktool android studio 调试 smali code, 重新打包
虽然有些菜单的位置跟新版的Android Stuido 3.4 有些不同,但是能用. https://crosp.net/blog/software-development/mobile/androi ...
- Linux学习笔记-第4天- linux命令有很多,不要求全会,常用的一定要能够熟练使用
linux命令就像单词,有很多.词汇量固然越大越好,但是常用基础命令一定要做到熟练应用. 同时学习不是死记硬背,排错能力同等重要,要理解其命令背后的运行机制,这样才能在翻车时 及时救场.
- linux数据库中使用MD5加密
MD5加密算法源码下载:https://pan.baidu.com/s/1nwyN0xV 下载完成了之后解压,得到两个文件 环境搭建: 1.把md5.h文件拷贝到/usr/include/目录下 su ...
- [LeetCode] 891. Sum of Subsequence Widths 子序列宽度之和
Given an array of integers A, consider all non-empty subsequences of A. For any sequence S, let the ...