安卓开发1

windows平台,已经安装了安卓SDK,eclipse(Eclipse Java EE IDE for Web Developers.Version: Luna Service Release 1 (4.4.1)),插件ADT

1)新建一个安卓项目,在eclipse中

file ->new ->project ->android ->android application project

点击next,下一个页面填写程序名(Application Name), 项目名(project Name),包名(package Name),注意包名要多层的,设置支持的最小版本SDK,最高版本SDK(target SDK),编译时用的SDK(一般是最高版),主题选择none(其他没试过),一直next,直到create activity,选择empty activity,点击next,设置activity Name,以及布局管理器名


2)开启安卓虚拟机,点击android virtual device manager,create,填写AVD参数,AVD名字,device是相关设备,target是安卓API版本,skin是屏幕尺寸像素,RAM不说了, 支持的VM heap是最大程序堆数,internal storage内置存储大小,


3)各个文件夹含义:

a)src文件夹中放的是activity程序,或者其他组件(以后加入的)

b)gen文件夹是自动生成的,用户不能修改,保存的是所有的ID,其中R.java文件中保存这所有的资源,这个文件时自动编写的

c)asset文件夹存放大型资源文件,一般不用,一般用res

d)res存放资源,其中drawable-hdpi等文件是存放图标图片的文件夹;layout文件夹内的xml文件存放布局管理器信息;values文件夹下的strings.xml中存放所有文字信息,里面有文字的名字和值,访问时用R.strings.文字名字,strings.xml中有个app_name是程序运行时在手机中显示的名字;AndroidManifest.xml文件是整个Android项目最重要的组成,它里面主要包括:xmlns:对应使用的sckema,package:程序所在的包,android:versionCode应用程序版本号,android:versionName:显示给用的版本号,minSdkVersion:支持的最低版本SDK,icon:图标文件名,label:在手机上程序显示的名字,android:name表示activity程序名;layout文件夹中的布局管理器xml文件中,LinearLayout表示布局管理器是线型布局的,与之对应的是相对布局(relativeLayout),android:orientation是组件布局方向,有VERTICAL, HORIZONTAL,android:layout_width表示组件宽度,可以是wrap_content表示和文字等宽,fill_parent表示和屏幕等宽,android:layout_height表示组件高度;常见组件有TextView文本组件,Button按钮组件,android:text表示组件显示的文字信息


4)配置组件属性,可以再layout文件夹下的布局管理器xml文件中进行,也可以在程序代码中实现

5)在布局管理器xml文件中进行,添加:

<TextView 
    android:id="@+id/mytext"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="good evening"/>
<Button
    android:id="@+id/but_morning"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:text="good evening"/>

6)在代码中实现,例如在src中Java文件中:

package org.yn.demo;


import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.*;
public class MyHello extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_hello);

// TextView text=(TextView)super.findViewById(R.id.mytext);
// text.setText(R.string.info);
// Button btn=(Button)findViewById(R.id.but_morning);
// btn.setText(R.string.btn_name);


LinearLayout lay=new LinearLayout(this);
lay.setOrientation(LinearLayout.HORIZONTAL);
TextView text=new TextView(this);
text.setText(super.getString(R.string.info));
Button btn=new Button(this);
btn.setText(super.getString(R.string.info));
lay.addView(text);
lay.addView(btn);
super.setContentView(lay);
}
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值