

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

本篇文章主要介绍 Android
开发中的部分知识点,通过阅读本篇文章,您将收获以下内容:
一、TextView 继承关系
二、TextView 简单使用举例
三、TextView 跑马灯效果
四、TextView末尾省略号属性
五、TextView 颜色、字体大小属性
六、TextView位置属性
七、TextView 包含图片超链 背景 垂直居中等属性
一、TextView 继承关系
TextView
继承关系如下:
java.lang.Object
↳ android.view.View
↳ android.widget.TextView
TextView
官网api
文档如下:

二、TextView 简单使用举例
使用 xml
布局跟java
代码动态设置TextView
。
-
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>
-
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
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
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
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
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="五、\n1.左侧包含图片 drawableLeft \n2.背景 颜色 白色 background \n3. 邮箱超链: autoLink eg :1150580768@qq.com"
android:textColor="@android:color/black"
android:textSize="16sp" />
实现效果如下:


至此,本篇已结束,如有不对的地方,欢迎您的建议与指正。同时期待您的关注,感谢您的阅读,谢谢!
如有侵权,请联系小编,小编对此深感抱歉,届时小编会删除文章,立即停止侵权行为,请您多多包涵。

网友评论