首頁  >  文章  >  後端開發  >  Android UI控制系列:TextView(文字方塊)

Android UI控制系列:TextView(文字方塊)

黄舟
黄舟原創
2017-01-19 09:24:311166瀏覽

TextView比較簡單,無法用來進行編輯,只能夠用來顯示訊息

版面配置檔案裡的一些常用的XML屬性

android:gravity—用來設定控制項內文字的對齊方式

android:layout_gravity—相對於父控制項來說,用於設定控制項的對齊方式

android:text—用來設定控制項文字資訊

android:layout_width—用來設定控制項的寬度

android:layout_height—用來設定控制項的高度

android:background—用來設定控制項的背景色

android:textColor—用來設定控制項內文字的顏色

android:textSize—用來設定控制項的文字字體大小

android:width和roidandroidand —功能與android:layout_width相似

區別:

android:layout_width只能設定fill_parent(橫向填充整個螢幕)或
wrap_content(橫向填充控製本身大小)

android:widthth設定特定控制項的橫向填充像素
例如: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);  
    }  
}

運行)的內容,更多相關內容請關注PHP中文網(www.php.cn)!

Android UI控制系列:TextView(文字方塊)

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn