学习 http://cs.szpt.edu.cn/android/training/basics/firstapp/building-ui.html#Button
android ui 元素的层次结构
两层UI结构:
<?xml version="1.0" encoding="utf-8"?> <!-- XML层次结构布局 LinearLayout ViewGroup --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation = "vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.hzxie.viewgroup.MainActivity" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id = "@+id/sub_edit_message" android:layout_weight = "1" android:layout_width="0dp" android:layout_height="wrap_content" android:hint="@string/sub_edit_message" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_send"/> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <!--控件唯一标识id,+仅在定义时使用,可以在Activity中find--> <EditText android:id = "@+id/edit_message" android:layout_weight = "1" android:layout_width="0dp" android:layout_height="wrap_content" android:hint="@string/edit_message" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button_send"/> </LinearLayout> </LinearLayout>
测试效果图: