一:如何自定义TextView实现滚动效果
  1. 继承TextView基类
  2. 重写构造方法
  3. 修改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>
三:总结
  1. 继承基类TextView
  2. 修改isFocused()方法
  3. 设置TextView属性

喜欢源码分析系列可参考其他文章:

Android源码分析(一)-----如何快速掌握Android编译文件

Android源码分析(二)-----如何编译修改后的framework资源文件

Android源码分析(三)-----系统框架设计思想

Android源码分析(四)-----Android源码编译及刷机步骤

Android源码分析(五)-----如何从架构师的角度去设计Framework框架

Android源码分析(十二)-----Android源码中如何自定义TextView实现滚动效果的更多相关文章

  1. ABP源码分析十二:本地化

    本文逐个分析ABP中涉及到locaization的接口和类,以及相互之间的关系.本地化主要涉及两个方面:一个是语言(Language)的管理,这部分相对简单.另一个是语言对应得本地化资源(Locali ...

  2. [Abp 源码分析]十二、多租户体系与权限验证

    0.简介 承接上篇文章我们会在这篇文章详细解说一下 Abp 是如何结合 IPermissionChecker 与 IFeatureChecker 来实现一个完整的多租户系统的权限校验的. 1.多租户的 ...

  3. jQuery 源码分析(十二) 数据操作模块 html特性 详解

    jQuery的属性操作模块总共有4个部分,本篇说一下第1个部分:HTML特性部分,html特性部分是对原生方法getAttribute()和setAttribute()的封装,用于修改DOM元素的特性 ...

  4. Vue.js 源码分析(十二) 基础篇 组件详解

    组件是可复用的Vue实例,一个组件本质上是一个拥有预定义选项的一个Vue实例,组件和组件之间通过一些属性进行联系. 组件有两种注册方式,分别是全局注册和局部注册,前者通过Vue.component() ...

  5. Heritrix源码分析(十二) Heritrix的控制中心(大脑)CrawlController(一)(转)

    本博客属原创文章,欢迎转载!转载请务必注明出处:http://guoyunsky.iteye.com/blog/650694 本博客已迁移到本人独立博客: http://www.yun5u.com/ ...

  6. MyBatis框架的使用及源码分析(十二) ParameterHandler

    在StatementHandler使用prepare()方法后,接下来就是使用ParameterHandler来设置参数,让我们看看它的定义: package org.apache.ibatis.ex ...

  7. Alink漫谈(二十二) :源码分析之聚类评估

    Alink漫谈(二十二) :源码分析之聚类评估 目录 Alink漫谈(二十二) :源码分析之聚类评估 0x00 摘要 0x01 背景概念 1.1 什么是聚类 1.2 聚类分析的方法 1.3 聚类评估 ...

  8. 一个普通的 Zepto 源码分析(二) - ajax 模块

    一个普通的 Zepto 源码分析(二) - ajax 模块 普通的路人,普通地瞧.分析时使用的是目前最新 1.2.0 版本. Zepto 可以由许多模块组成,默认包含的模块有 zepto 核心模块,以 ...

  9. Zepto源码分析(二)奇淫技巧总结

    Zepto源码分析(一)核心代码分析 Zepto源码分析(二)奇淫技巧总结 目录 * 前言 * 短路操作符 * 参数重载(参数个数重载) * 参数重载(参数类型重载) * CSS操作 * 获取属性值的 ...

随机推荐

  1. 多线程(五)多线程同步_Event事件

    事件和互斥体同样属于内核同步对象,它和互斥体以及临界区在功能上有以下区别 前面的互斥体和临界区主要作用在于确保控制多个线程之间对共享资源访问,保证共享资源的完整性 事件主要作用是通知其它线程一个操作己 ...

  2. 【Spring IoC】依赖注入DI(四)

    平常的Java开发中,程序员在某个类中需要依赖其它类的方法.通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理. Spring提出了依赖注入的思想,即依赖类不由程 ...

  3. Provider和Consumer的搭建(六)

    创建三个Maven Project: dubbo-service:公共模块,包括服务接口(packaging:jar) dubbo-service-impl:服务提供方,提供服务接口的具体实现,需要依 ...

  4. centos7中运行ifconfig提示“-bash: ifconfig: command not found”解决方案

    linux系统查看ip地址常用命令是[ifconfig], CentOS 7.0最小安装是没有ifconfig命令怎么办? 1.用[ip addr]查看; 2.就是安装ifconfig命令 1.输入[ ...

  5. 【转】K-Means聚类算法原理及实现

    k-means 聚类算法原理: 1.从包含多个数据点的数据集 D 中随机取 k 个点,作为 k 个簇的各自的中心. 2.分别计算剩下的点到 k 个簇中心的相异度,将这些元素分别划归到相异度最低的簇.两 ...

  6. React Hooks 深入系列

    本文基于近段时间对 hooks 碎片化的理解作一次简单梳理, 个人博客.同时欢迎关注基于 hooks 构建的 UI 组件库 -- snake-design. 在 class 已经融入 React 生态 ...

  7. html5手机web页面底部菜单

    一.效果图 二.HTML代码 <header class="text-center">TOP</header> <div id="conte ...

  8. .net core —— 控制台如何获取配置文件的内容?

    本文链接:https://blog.csdn.net/yenange/article/details/82457761参考: https://github.com/liuzhenyulive/Json ...

  9. 【07月15日】A股滚动市盈率PE最低排名

    ​仅根据最新的市盈率计算公式进行排名,无法对未来的业绩做出预测. 方大集团(SZ000055) - 滚动市盈率PE:2.53 - 滚动市净率PB:1.13 - 滚动年化股息收益率:4.01% - 建筑 ...

  10. Serverless 与容器决战在即?有了弹性伸缩就不一样了

    作者 | 阿里云容器技术专家 莫源  本文整理自莫源于 8 月 31 日 K8s & cloudnative meetup 深圳场的演讲内容.****关注"阿里巴巴云原生" ...