TextView 使用詳解

和你一起終身學(xué)習(xí),這里是程序員Android
經(jīng)典好文推薦,通過閱讀本文,您將收獲以下知識(shí)點(diǎn):
一、TextView 簡介
二、TextView 簡單使用方法
三、TextView 跑馬燈效果
四、TextView末尾省略號(hào)屬性
五、TextView 顏色、字體大小屬性
六、TextView位置屬性
七、TextView 包含圖片超鏈 背景 垂直居中等屬性
一、TextView 簡介
在學(xué)習(xí)TextView 之前,我們先了解一下TextView的繼承關(guān)系。TextView?繼承關(guān)系如下:
java.lang.Object
? android.view.View
? android.widget.TextView
TextView 主要用來顯示文字內(nèi)容,是Android 入門最基礎(chǔ)的控件之一。
二、TextView 簡單使用方法
使用?xml?布局跟java代碼動(dòng)態(tài)設(shè)置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>
2.?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 跑馬燈效果
1.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 歡迎關(guān)注 程序員Android 獲取更多Android 開發(fā)資料、干貨、學(xué)習(xí)視頻!"
android:textSize="16sp" />
2.實(shí)現(xiàn)效果如下:

TextView 跑馬燈效果
四、TextView末尾省略號(hào)屬性
1.TextView末尾省略號(hào)屬性實(shí)現(xiàn)如下:
<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="二、末尾省略號(hào)效果 eg:ellipsize 屬性 控制 省略號(hào)的位置 (開始 中間 結(jié)尾 跑馬燈) "
android:textSize="16sp" />
2.實(shí)現(xiàn)效果如下:

TextView 末尾省略號(hào)屬性實(shí)現(xiàn)
五、TextView 顏色、字體大小屬性
1.TextView?字體顏色、大小設(shè)置如下:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="三、字體顏色、字體大小 eg:textColor 紅色 textSize 16sp"
android:textColor="#F00"
android:textSize="16sp" />
2. 實(shí)現(xiàn)效果如下:

TextView 字體顏色與大小
六、TextView位置屬性
1.TextView位置居中屬性設(shè)置如下:
<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" />
2.實(shí)現(xiàn)效果如下:

TextView 位置居中屬性設(shè)置
七、TextView 包含圖片超鏈 背景 垂直居中等屬性
1.TextView設(shè)置超鏈點(diǎn)擊,左側(cè)圖片、垂直居中等屬性如下:
<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.左側(cè)包含圖片 drawableLeft \n2.背景 顏色 白色 background \n3. 郵箱超鏈:autoLink eg :[email protected]"
android:textColor="@android:color/black"
android:textSize="16sp" />
2.實(shí)現(xiàn)效果如下:

TextView 超鏈 圖片等屬性
至此,本篇已結(jié)束。轉(zhuǎn)載網(wǎng)絡(luò)的文章,小編覺得很優(yōu)秀,歡迎點(diǎn)擊閱讀原文,支持原創(chuàng)作者,如有侵權(quán),懇請(qǐng)聯(lián)系小編刪除。同時(shí)感謝您的閱讀,期待您的關(guān)注。
點(diǎn)個(gè)在看,方便您使用時(shí)快速查找!
評(píng)論
圖片
表情
