安卓Activity布局簡述

來源:互聯網
上載者:User

標籤:.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布局簡述

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.