Android 文本视图TextView
来源:互联网 发布:2017手机淘宝主图尺寸 编辑:程序博客网 时间:2024/05/23 20:54
TextView想必大家都很熟悉了,不管在哪门语言中,文本显示是最为基础的。TextView的基本属性有很多,我就不一一介绍了。这里我们直接通过几个例子来看下TextView的使用。
1.TextView跑马灯效果,这个示例是实现文字滚动效果。
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.easygoing.androidtextview.MainActivity"> <com.easygoing.androidtextview.ScrollingTextView android:id="@+id/tv_marquee" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="30dp" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:clickable="true" android:focusableInTouchMode="true" android:textSize="18sp" android:marqueeRepeatLimit="10" android:text="静静绽放 吐露芬芳 无论什么境况 静静绽放吐露芬芳" /></LinearLayout>这里我简单自定义了一个TextView,让TextView一直拥有焦点,从而使跑马灯效果不停止。
package com.easygoing.androidtextview;import android.content.Context;import android.graphics.Rect;import android.util.AttributeSet;import android.widget.TextView;import org.jetbrains.annotations.Nullable;/** * Created by Lenovo on 2017/11/15. */public class ScrollingTextView extends TextView { private Context context; public ScrollingTextView(Context context) { super(context); } public ScrollingTextView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); } public ScrollingTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); this.context = context; } @Override protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { if(focused) super.onFocusChanged(focused, direction, previouslyFocusedRect); } @Override public void onWindowFocusChanged(boolean hasWindowFocus) { if(hasWindowFocus) super.onWindowFocusChanged(hasWindowFocus); } @Override public boolean isFocused() { return true; }}
让我们看下效果图:
其中这几个属性是必须要设置的:
android:singleLine="true" //指定文本单行显示android:ellipsize="marquee"//指定文本超出范围后的省略方式--start:省略号在开头 middle:省略号在中间 end:省略号在末尾 marquee:跑马灯显示android:focusable="true"//指定是否获得焦点,跑马灯效果必须为trueandroid:focusableInTouchMode="true"//指定在触摸时获得焦点,跑马灯效果必须为true
2.TextView搜索框
这里我们简单实现一个搜索框,它有默认的背景色,以及按下的背景色。实例如下图:
代码也很简单:
当然光有布局是不行的,下面我将selector的内容放出来。
另外两个就比较简单了,只是设置下按下时候的背景或文字颜色。
好了,TextView就到这里了。
阅读全文
0 0
- Android 文本视图TextView
- Android UI 控件详解-TextView(文本视图)
- TextView:文本视图。
- Android文本显示:TextView
- Android TextView富文本
- android TextView 文本不同颜色
- android textview富文本
- Android TextView格式化文本
- Android TextView Justify Text TextView自适应文本
- Android TextView 文本自动对齐
- Android TextView 文本折叠效果
- Android TextView 文本折叠效果
- Android TextView 文本折叠效果
- android textview 显示 文本 .txt
- Android显示TextView文本控件
- android textview 文本显示不同颜色
- Android中TextView富文本
- android:TextView设置文本样式和超链接
- 依赖,libry
- 【DevExpress v17.2新功能预告】增强ASP.NET GridView的功能
- 谷歌移动端深度学习框架TensorFlow Lite正式发布
- 24时区来源,CST,CET,UTC,DST,Unix时间戳概述、关系、转换
- Android8.0 WIFI ap Tethering 相关知识
- Android 文本视图TextView
- 洛谷P2045:方格取数加强版
- android播放swf文件
- mybactis多对一
- window 安装 sass compass 记录
- Idea环境下SpringBoot发布war
- HBase之get方法
- 如何改进脚本下载
- maven 配置 ueditor