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); } }
執行結果:
相關文章
- §2.1 最常用的控制元件------文字框(TextView)控制元件TextView
- Android:TextView控制元件AndroidTextView控制元件
- Android UI控制元件系列:Toast(提示)AndroidUI控制元件AST
- Android TextView格式化文字AndroidTextView
- Android Vertical TextView 文字豎排AndroidTextView
- Android UI控制元件系列:Button(按鈕)AndroidUI控制元件
- Android UI控制元件系列:TableLayout(表格佈局)AndroidUI控制元件
- Android UI控制元件系列:Spinner(下拉選單)AndroidUI控制元件
- Android UI控制元件系列:ProgressBar(進度條)AndroidUI控制元件
- 【Android 】TextView 區域性文字變色AndroidTextView
- Android--TextView 文字顯示和修改AndroidTextView
- Android UI控制元件系列:Gallery(畫廊檢視)AndroidUI控制元件
- Android UI控制元件系列:TabWidget(切換卡)AndroidUI控制元件
- Android UI控制元件系列:WebView(網路檢視)AndroidUI控制元件WebView
- Android UI控制元件系列:AutoCompleteTextView(自動提示)AndroidUI控制元件TextView
- Android UI控制元件系列:Tab Layout(選項卡布局)AndroidUI控制元件
- Android UI控制元件系列:RelativeLayout(相對佈局)AndroidUI控制元件
- Android UI控制元件系列:GridView(網格佈局)AndroidUI控制元件View
- Android UI控制元件系列:Dialog(對話方塊)AndroidUI控制元件
- Android UI控制元件系列:LinearLayout(線性佈局)AndroidUI控制元件
- Android UI控制元件系列:ImageButton(帶圖示的按鈕)AndroidUI控制元件
- Android UI控制元件系列:RadioButton(單選按鈕)AndroidUI控制元件
- 教你如何實現 Android TextView 文字輪播效果AndroidTextView
- 詳細實現微信輸入框效果(textView自適應文字高度)TextView
- 文字太多?控制元件太小?試試 TextView 的新特性 Autosizing 吧!控制元件TextView
- TextView、TextView的子類之EditText、EditText的子類之自動完成文字框(AutoCompleteTextView)的功能與用法TextView
- Android開發筆記——TextView文字設定不同顏色Android筆記TextView
- Android入門教程 | TextView簡介(寬高、文字、間距)AndroidTextView
- Android TextView 富文字之 android.text.style.xxxSpanAndroidTextView
- Android之TextView設定drawableRight等圖片文字間隔AndroidTextView
- Android開發之TextView文字水平滾動效果實現AndroidTextView
- UI之可摺疊的TextViewUITextView
- TextView搜尋文字高亮顯示TextView
- 在TextView使用部分顏色文字TextView
- Android UI控制元件系列:DatePicker,TimePicker(日期和時間選擇)AndroidUI控制元件
- Android 介面(1):UI 開發控制元件AndroidUI控制元件
- Android UI 設計(4):EditText 控制元件AndroidUI控制元件
- Android FixedTextView 字型大小自適應文字框AndroidTextView