標籤:.text 文字 按鈕 linear line 安卓 apk ext 重寫
Activity布局簡述
基於xml的布局
Main.xml(調用工程res/layout/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" ><!--線形布局--> <ImageButton android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="wrap_content模式" android:src="@drawable/ic_launcher" /><!--將某映像顯示在按鈕上--> <Button android:id="@+id/button2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="fill_parent模式" /><!--這個按鈕顯示為fill_parent模式 --> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Hello World, MyActivity" /> </LinearLayout> |
基於Activity的布局
package com.example.myapp1;
import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.widget.TextView; //系統預設產生的Activity源碼檔案的內容大致如下
public class MyActivity extends Activity { /** * Called when the activity is first created. */ @Override //表示重寫這個onCreate方法(使用onCreat()建立相應的Activity,這個方法一般是必須的;) // Bundle儲存了應用程式上次關閉時的狀態,並且可以通過一個Activity 傳給另一個Activity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv=new TextView(this); tv.setText("你好");//設定顯示文字 tv.setTextSize(48.0f);//設定字型大小 tv.setTextColor(Color.BLUE);//設定字型顏色 setContentView(tv);//語句參數為執行個體對象名,而不是xml布局檔案 } }
|
安卓Activity布局簡述