android入门与实践

ActivityMain.java

package com.android.layout;

 

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ActivityMain extends Activity {
    /** Called when the activity is first created. */
 OnClickListener listener0 = null;
 OnClickListener listener1 = null;
 OnClickListener listener2 = null;
 OnClickListener listener3 = null;
 Button button0;
 Button button1;
 Button button2;
 Button button3;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        listener0 = new OnClickListener() {
   public void onClick(View v) {
    Intent intent0 = new Intent(ActivityMain.this, ActivityFrameLayout.class);
    setTitle("FrameLayout");
    startActivity(intent0);
   }
  };
  listener1 = new OnClickListener() {
   public void onClick(View v) {
    Intent intent1 = new Intent(ActivityMain.this, ActivityRelativeLayout.class);
    startActivity(intent1);
   }
  };
  listener2 = new OnClickListener() {
   public void onClick(View v) {
    setTitle("这是在ActivityLayout");
    Intent intent2 = new Intent(ActivityMain.this, ActivityLayout.class);
    startActivity(intent2);

   }
  };
  listener3 = new OnClickListener() {
   public void onClick(View v) {
    setTitle("TableLayout");
    Intent intent3 = new Intent(ActivityMain.this, ActivityTableLayout.class);
    startActivity(intent3);

   }
  };
  setContentView(R.layout.main);
  button0 = (Button) findViewById(R.id.button0);
  button0.setOnClickListener(listener0);
  button1 = (Button) findViewById(R.id.button1);
  button1.setOnClickListener(listener1);
  button2 = (Button) findViewById(R.id.button2);
  button2.setOnClickListener(listener2);
  button3 = (Button) findViewById(R.id.button3);
  button3.setOnClickListener(listener3);
    }
}

 

strings.xml

 

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, ActivityMain!</string>
    <string name="app_name">TestMain</string>
    <drawable name="red">#7f00</drawable>
 <drawable name="blue">#770000ff</drawable>
 <drawable name="green">#7700ff00</drawable>
 <drawable name="yellow">#77ffff00</drawable>
</resources>

 

ActivityLayout.java

 

package com.android.layout;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class ActivityLayout extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  LinearLayout layoutMain = new LinearLayout(this);
  layoutMain.setOrientation(LinearLayout.HORIZONTAL);
  setContentView(layoutMain);
  LayoutInflater inflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  RelativeLayout layoutLeft = (RelativeLayout) inflate.inflate(
    R.layout.left, null);
  RelativeLayout layoutRight = (RelativeLayout) inflate.inflate(
    R.layout.right, null);

  RelativeLayout.LayoutParams relParam = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT,
    RelativeLayout.LayoutParams.WRAP_CONTENT);
  layoutMain.addView(layoutLeft, 100, 100);
  layoutMain.addView(layoutRight, relParam);
 }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值