zoukankan      html  css  js  c++  java
  • TextView 使用详解

    极力推荐文章:欢迎收藏
    Android 干货分享

    阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android

    本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以下内容:

    一、TextView 继承关系
    二、TextView 简单使用举例
    三、TextView 跑马灯效果
    四、TextView末尾省略号属性
    五、TextView 颜色、字体大小属性
    六、TextView位置属性
    七、TextView 包含图片超链 背景 垂直居中等属性

    一、TextView 继承关系

    TextView 继承关系如下:

    java.lang.Object
       ↳	android.view.View
     	   ↳	android.widget.TextView
    

    TextView 官网api 文档如下:

    点击查 TextView 文档

    二、TextView 简单使用举例

    使用 xml 布局跟java代码动态设置TextView

      1. xml 布局如下
     <LinearLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent">
        <TextView
            android:id="@+id/text_view_id"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="@string/hello" />
     </LinearLayout>
    
      1. java 代码中使用方法如下:
     public class MainActivity extends Activity {
    
        protected void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             setContentView(R.layout.activity_main);
             final TextView helloTextView = (TextView) findViewById(R.id.text_view_id);
             helloTextView.setText(R.string.user_greeting);
         }
     }
     
    

    三、TextView 跑马灯效果

    TextView 跑马灯 效果使用方法如下:

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:text="一、跑马灯 效果  eg:ellipsize 欢迎关注 程序员Android  获取更多Android 开发资料、干货、学习视频!"
            android:textSize="16sp" />
    

    实现效果如下:
    TextView 跑马灯效果

    四、TextView末尾省略号属性

    TextView末尾省略号属性实现如下:

    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:paddingBottom="10dp"
            android:paddingTop="10dp"
            android:singleLine="true"
            android:text="二、末尾省略号效果   eg:  ellipsize 属性 控制  省略号的位置  (开始 中间 结尾 跑马灯)  "
            android:textSize="16sp" />
    

    实现效果如下:
    TextView 末尾省略号属性实现

    五、TextView 颜色、字体大小属性

    TextView 字体颜色、大小设置如下:

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="三、字体颜色、字体大小 eg:textColor 红色  textSize 16sp"
            android:textColor="#F00"
            android:textSize="16sp" />
    

    实现效果如下:
    TextView 字体颜色与大小

    六、TextView位置属性

    TextView 位置居中属性设置如下:

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:paddingBottom="10dp"
            android:paddingTop="10dp"
            android:text="四、字体位置属性  eg:居中 "
            android:textColor="#FF6100"
            android:textSize="16sp" />
    

    实现效果如下:
    TextView 位置居中属性设置

    七、TextView 包含图片超链 背景 垂直居中等属性

    TextView 设置超链点击,左侧图片、垂直居中等属性如下:

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:autoLink="email"
            android:background="@android:color/white"
            android:drawableLeft="@drawable/ic_launcher"
            android:gravity="center_vertical"
            android:linksClickable="true"
            android:text="五、
    1.左侧包含图片  drawableLeft 
    2.背景 颜色  白色  background 
    3. 邮箱超链:  autoLink eg :1150580768@qq.com"
            android:textColor="@android:color/black"
            android:textSize="16sp" />
    
    

    实现效果如下:
    TextView 超链  图片等属性

    至此,本篇已结束,如有不对的地方,欢迎您的建议与指正。同时期待您的关注,感谢您的阅读,谢谢!

    微信关注公众号:  程序员Android,领福利

  • 相关阅读:
    js实现截图并下载到本地
    div里面的文本内容居中显示
    div里面的p标签内容上下垂直居中
    《将博客搬至CSDN》
    RobotFramework 用例出错后继续操作
    selenium+log4j+eclipse相关问题及解决方案
    linux 安装maven
    LINUX下查看系统参数的常见命令
    Linux常用命令使用
    grep 命令
  • 原文地址:https://www.cnblogs.com/wangjie1990/p/11310801.html
Copyright © 2011-2022 走看看