TextView講解

 代碼和配置文件:

package com.oyzz.ch3;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class Ch3 extends Activity {
 //聲明一個TextView對象,TextView相當swing裏的label標籤
 private TextView textView = null ;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
     
        super.onCreate(savedInstanceState);//可以不調用
       
        setContentView(R.layout.main); //加載main.xml配置文件裏的layout主界面的佈局方式
       
        textView = (TextView) findViewById(R.id.textView);//根據id創建對象TextView
       
        TextView textView1 = (TextView) findViewById(R.id.textView1);//根據id創建對象TextView
       
        textView1.setText("<請點擊訪問:http://nba.tom.com/");
       
        //textView.setTextSize(7);//字體的大小
    }
}

 

main.xml配置文件:

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget35"
    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/myTextView"
    android:id="@+id/textView"
    />
    <TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/textView1"
    android:layout_x="50px"
    android:layout_y="100px"
    android:autoLink="all"
    />
</AbsoluteLayout>

strings.xml配置文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="myTextView">歡迎使用TextView,我在配置文件中</string>
    <string name="app_name">Ch3</string>
</resources>

學習體會總結:

1.首先該控件相當是swing裏的jlabel標籤顯示控件,用來顯示文本之類的。

2.對android工程的一個初步認識:

   1.首先要實現android程序,則必須得實現Activity中的onCreate()方法
  
   2.mian.xml配置文件,主要是用來實現對整個界面進行佈局,然後就是還有在這裏配置出那個具體控件的屬性(包括位置,id
   大小,顯示的文本,當然這些可以到代碼裏面直接的進行設置,但是如果到配置文件裏的話,爲以後的調節和國際化之類的就提
   供了有利的保證,另外注意的就是配置文件裏的設置低於代碼裏的)
  
   3.R.java自動生成的文件裏的,可以將mian.xml配置文件的id自動生成對應的id類,以便於findViewById方法查找調用,
   還有就是會生成對應的drawable(顏色),layout(佈局),string(字符串)。
  
   4.strings.xml配置文件是用來配置字符串的,支持國際化用的。會在對應的R.java string中生成對應的id。
  
   5.findViewById根據id來查找值。
  
   6.TextView本身不支持html標籤,如果要使用鏈接的話,直接使用android:autoLink="all"標記即可,他會自動的完成鏈
    接的功能

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章