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


               }
    }

     

  • 相关阅读:
    Conda 使用笔记
    个人日志笔记软件比较
    CMD 命令笔记
    Joplin 资源汇总
    【NAS】Hexo+Github 搭建博客&基础配置
    【NAS】群晖 WordPress 使用记录
    哈工大计组mooc 第四章 中 测试
    下列软件包有未满足的依赖关系:
    安装ubuntu用Ultraiso制作引导盘便捷启动提示:找到多余一个分区
    ros安装caffe anaconda2之后roscore无法执行
  • 原文地址:https://www.cnblogs.com/sinceForever/p/8454367.html
Copyright © 2011-2022 走看看