初学者
来源:互联网 发布:安徽省大数据会员单位 编辑:程序博客网 时间:2024/04/28 17:55
- package org.kevin.android;
- import android.app.Activity;
- import android.os.Bundle;
- //HelloAndroid.java
- public class HelloAndroid extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- }
- }
这个类继承自activity,重载了它的方法onCreate(),其中方法中有一个参数它是activity之前传递数据用的,不知道是不是这样,反正是我理解的,理解万岁!setContentView()方法是布局整个View的此处R.layout.main找到了main.xml,将其显示在屏幕上。Android通过R类找到一些资源,下面是R类的代码
- /* AUTO-GENERATED FILE. DO NOT MODIFY.
- *
- * This class was automatically generated by the
- * aapt tool from the resource data it found. It
- * should not be modified by hand.
- */
- package org.kevin.android;
- public final class R {
- public static final class attr {
- }
- public static final class drawable {
- public static final int icon=0x7f020000;
- }
- public static final class layout {
- public static final int main=0x7f030000;
- }
- public static final class string {
- public static final int app_name=0x7f040001;
- public static final int hello=0x7f040000;
- }
- }
可见Android的activity是通过R找到rec文件夹下的资源的,
那如果想找到app_name的话,只需写R.string.app_name,貌似很简单,
下面在看一下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"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello"
- />
- </LinearLayout>
linearlayout是否是线性布局呢?理解万岁!里面只有一个textview宽为覆盖整个父框架,高为根据内容,内容为string下的hello ID的值。哦出来string了,那不得不看看string.xml
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <string name="hello">Hello World, HelloAndroid!</string>
- <string name="app_name">HelloAndroid</string>
- </resources>
果然找到了一个名叫hello的string 其值为Hello World,HelloAndroid!
经过分析,我们貌似得出了一个结论,执行次工程,屏幕上必然显示Hello World,HelloAndroid!
提前忘截图了- -!
- 初学者
- 初学者
- 初学者
- 初学者
- 初学者!
- 初学者
- 初学者
- 初学者
- 初学者
- 初学者
- 初学者
- 初学者
- 初学者
- 初学者
- 初学者
- 初学者
- 初学者
- 初学者
- 《货币战争2-金权天下》杂录。。这本书读了之后我觉得有点对努力和奋斗失去信心,所以。
- 我的暑假
- 汇编指令大全及标志位
- Introduction
- android构建自定义的视图组件
- 初学者
- "不要自己发明轮子"与"了解轮子是如何发明的"
- 寻求答案
- 天遇到个问题,后面在框架中,当判断登录失效后要返回登录页面
- 命名空间(namespace)
- 类的设计2
- 看看我什么时候能水过100 1045
- 1068
- 1028 12th