下面我們來看一下它的具體用法。
佈局文件中的代碼,如下所示:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" //縱向佈局
android:layout_width="match_parent" //當前控件大小與父佈局的大小一致
android:layout_height="match_parent">
<TextView
android:id="@+id/textview" //唯一標識符
android:layout_width="match_parent"
android:layout_height="wrap_content" //控件內容決定當前控件大小
android:gravity="center" //字的對齊方式
android:textSize="24dp" //字體大小
android:textColor="#ff0" //字體顏色
android:text="This is Textview!" //設置顯示的內容
</ Linearlayout>
運行圖如下: