zoukankan      html  css  js  c++  java
  • 安卓Activity布局简述

    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布局文件


               }
    }

     

  • 相关阅读:
    1. Java 基础概念
    IDEA 插件
    IDEA 初始化配置
    二叉查找树
    阿里云安装Redis教程与相关问题
    H2知识小结
    重装VisualSVN Server报错
    linux(centos6.10)下去掉mysql的强密码验证
    TP-LINK路由器端口映射全套教程(亲测有效)
    idea2018.3.6,离线使用maven的方法
  • 原文地址:https://www.cnblogs.com/sinceForever/p/8454367.html
Copyright © 2011-2022 走看看