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


               }
    }

     

  • 相关阅读:
    SSIS数据同步实践
    不同实例下同构表数据同步验证
    Performance Analysis of Logs (PAL) Tool
    scrapy框架_3持久化存储
    scrapy框架_2数据解析案例_最新糗事百科案例
    scrapy框架_简单基础命令操作
    Selenium 模块3经典案例_规避检测_js写入破解服务器Selenium识别 模拟登陆12306登陆
    Selenium 模块2_iframe处理_动作链
    Selenium 模块
    Flask_模板
  • 原文地址:https://www.cnblogs.com/sinceForever/p/8454367.html
Copyright © 2011-2022 走看看