项目目录结构:
AndroidManifest.xml
src/
Activity
class that runs when your app is launched using the app icon.
res/
- 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.
- Directory for files that define your app's user interface.
- Directory for other various XML files that contain a collection of resources, such as string and color definitions.
drawable-hdpi/
layout/
values/
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
).
+
) 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等会再补充完。。。。