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操作 * 获取属性值的 ...
随机推荐
- zz从Word Embedding到Bert模型—自然语言处理中的预训练技术发展史
从Word Embedding到Bert模型—自然语言处理中的预训练技术发展史 Bert最近很火,应该是最近最火爆的AI进展,网上的评价很高,那么Bert值得这么高的评价吗?我个人判断是值得.那为什么 ...
- USACO Stamps
洛谷 P2725 邮票 Stamps https://www.luogu.org/problem/P2725 JDOJ 1797: Stamps 邮票 https://neooj.com:8082/o ...
- SSH使用ProxyCommand通过代理服务器远程连接其他服务器
当前环境拓扑图: 用户管理海外服务器,通过公网SSH远程时,由于网络质量原因公网丢包严重,这就导致管理员在对海外云主机进行管理时体验较差,表现形式可能是由于公网丢包严重执行命令卡顿,或者SSH进程 ...
- 树莓派跑yolo
https://blog.csdn.net/u011304078/article/details/85772764 https://blog.csdn.net/weixin_41665225/arti ...
- 公共组件及脚手架webpack模板
一.公共组件的创建和使用 前面已经学习vue组件时,了解了公共组件,但在脚手架项目中只使用过局部组件.这里是讲解全局组件如何在脚手架项目中去使用. 1.创建全局组件 在src/components/C ...
- [LeetCode] 876. Middle of the Linked List 链表的中间结点
Given a non-empty, singly linked list with head node head, return a middle node of linked list. If t ...
- 团队作业第五次—项目冲刺-Day2
Day2 part1-SCRUM: 项目相关 作业相关 具体描述 所属班级 2019秋福大软件工程实践Z班 作业要求 团队作业第五次-项目冲刺 作业正文 hunter--冲刺集合 团队名称 hunte ...
- x58平台 服务器电源配置 tdp
我的机器配置: 处理器: Intel(R) Xeon(R) CPU X5660 @ 2.80GHz *2主板: TYAN Tyan Tank GT20-B7002LN ...
- 【沙龙报名中】与微信&云开发官方团队零距离互动,揭秘爆款微信小游戏背后的技术!
有人说 微信小程序游戏的百花齐放 活像十几年前的4399小游戏称霸互联网的景象 " 歪,斗地主吗,三缺二, 不用下app,小程序就能玩,我保证不抢地主让你抢!" ...... &q ...
- 2条最佳实践App疯狂增长逻辑
2条最佳实践App疯狂增长逻辑 1.不断打造和强化产品的不可或缺属性 产品的核心价值是什么?对你的客户来言,为什么是你? 2.等待“阿哈时刻” 进入快速推广 用户使用产品眼前一亮的时刻,是用户真正发现 ...