Andriod学习笔记(1)

项目目录结构:

AndroidManifest.xml
The  manifest file describes the fundamental characteristics of the app and defines each of its components. You'll learn about various declarations in this file as you read more training classes.
src/
Directory for your app's main source files. By default, it includes an  Activity class that runs when your app is launched using the app icon.
res/
Contains several sub-directories for  app resources. Here are just a few:
drawable-hdpi/
Directory for drawable objects (such as bitmaps) that are designed for high-density (hdpi) screens. Other drawable directories contain assets designed for other screen densities.
layout/
Directory for files that define your app's user interface.
values/
Directory for other various XML files that contain a collection of resources, such as string and color definitions.

actity.xml

<EditText android:id="@+id/edit_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/edit_message" />

The at sign (@) is required when you're referring to any resource object from XML. It is followed by the resource type (id in this case), a slash, then the resource name (edit_message).

The plus sign ( +) before the resource type is needed only when you're defining a resource ID for the first time.  When you compile the app, the SDK tools use the ID name to create a new resource ID in your project's gen/R.java file that refers to the EditText element. Once the resource ID is declared once this way, other references to the ID do not need the plus sign.

"wrap_content" 根据内容自适应最大。

andriod:hint:文本框为空的时候,显示的文字。

android:layout_weight 内容为数字,指明每个view占的比重,默认为0.。
比如,有两个控件,一个weight为1,一个为2,则一个占三分之一,一个占三分之二,如果这时有第三个控件,weight为1加入,则第一个占四分之一,第二个占二分之一,第三个占四分之一。
如果只给一个控件分配了weight那么这个控件就会占用其他控件用剩的所有剩余空间。

===========================神奇的分割线================================


做了这么个界面

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <EditText
        android:id="@+id/edit_message"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:hint="@string/edit_message" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_send"
        android:onClick="sendMessage"/>

</LinearLayout>

然后给Button加上事件

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_send"
    android:onClick="sendMessage" />

在MainActity类中增加sendMessage方法

方法必须是public,返回值为void,参数为View类型

Intent是一个用来在运行是绑定不同的对象的
如在sendMessage中绑定一个Activity

Intent intent = new Intent(this, DisplayMessageActivity.class);
第一个参数是context这里就是MainActivity,第二个参数是应用组件

Intent不仅仅可以让你开始另一个activity,它也可以为activity带来很多数据信息。

Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);


R那个类好像是通过xml文件自动生成的,可以有各种的组件的id信息(猜的,等下查查)

然后跳转到另外一个activity等会再补充完。。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值