Android UI控制元件系列:TextView(文字框)
TextView比較簡單,不能夠用來進行編輯,只能夠用來顯示資訊
佈局檔案裡的一些常用的XML屬性
android:gravity—用來設定控制元件內文字的對齊方式
android:layout_gravity—相對於父控制元件來說,用於設定控制元件的對齊方式
android:text—用來設定控制元件文字資訊
android:layout_width—用來設定控制元件的寬度
android:layout_height—用來設定控制元件的高度
android:background—用來設定控制元件的背景色
android:textColor—用來設定控制元件內文字的顏色
android:textSize—用來設定控制元件的文字字型大小
android:width和android:height—功能與android:layout_width相似
區別:
android:layout_width只能設定fill_parent(橫向填充整個螢幕)或
wrap_content(橫向填充控制元件本身大小)
android:width設定具體控制元件的橫向大小 單位是畫素
例如:TextView顯示
main.xml佈局檔案
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout>
string.xml檔案
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World, MyTestView!</string> <string name="app_name">MyTestView</string> </resources>
MyTextView.java檔案
package org.loulijun.MyTestView; import android.app.Activity; import android.os.Bundle; public class MyTestView extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
執行結果:
相關文章
- Android TextView 富文字之 android.text.style.xxxSpanAndroidTextView
- 教你如何實現 Android TextView 文字輪播效果AndroidTextView
- Android之TextView設定drawableRight等圖片文字間隔AndroidTextView
- Android開發筆記——TextView文字設定不同顏色Android筆記TextView
- Android入門教程 | TextView簡介(寬高、文字、間距)AndroidTextView
- TextView、TextView的子類之EditText、EditText的子類之自動完成文字框(AutoCompleteTextView)的功能與用法TextView
- Android FixedTextView 字型大小自適應文字框AndroidTextView
- Android元件詳解—TextViewAndroid元件TextView
- android炫酷的textviewAndroidTextView
- 短影片app原始碼,Android TextView文字,刪除線以及下劃線APP原始碼AndroidTextView
- 【Android初級】使用TypeFace設定TextView的文字字型(附原始碼)AndroidTextView原始碼
- Android 高亮關鍵字TextViewAndroidTextView
- Android:TextView maxWidth maxLines maxLength maxEmsAndroidTextView
- Android中TextView及其子類AndroidTextView
- Android自定義控制元件 帶文字提示的SeekBarAndroid控制元件
- Selenium4+Python3系列(八) - Cookie、截圖、單選框及核取方塊處理、富文字框、日曆控制元件操作PythonCookie控制元件
- 富文字框
- android基礎學習-android篇day12-UI基礎控制元件(上)AndroidUI控制元件
- android基礎學習-android篇day13-UI基礎控制元件(下)AndroidUI控制元件
- 動態新增或減少文字框,並獲取文字框值
- Android開發筆記——TextView 多行時 ellipsizeAndroid筆記TextView
- Android入門教程 | Button,TextView背景設定AndroidTextView
- 聊天平臺原始碼,TextView部分文字變色原始碼TextView
- (原創)【B4A】一步一步入門07:EditText,文字框、密碼框、鍵盤樣式、提示文字(控制元件篇03)密碼控制元件
- 文字框和標籤
- CSS 文字框圓角CSS
- 文字框輸入文字倒計詳解
- Android Textview 一行居中 兩行居左AndroidTextView
- Android TextView 在指定位置自動省略字元AndroidTextView字元
- TextView自定義輕鬆實現下劃線、點選彈框TextView
- CSS input 文字框樣式CSS
- CSS input文字框樣式CSS
- CSS匹配input text文字框CSS
- HTML textarea 多行文字框HTML
- Python文字框與按鈕Python
- 文字框文字輸入數量倒計效果
- SAP UI5 XML 檢視裡 label 和 text 控制元件文字對齊問題UIXML控制元件
- Android更換APP字型—TextView各種字型樣式AndroidAPPTextView
- UWP 自定義密碼框控制元件密碼控制元件