1.常见布局
- 1.1 线性布局 LinearLayout
右键–>创建Android XML File
根节点:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"//宽度,填充父框体
android:layout_height="wrap_content"//高度,包裹内容
android:gravity="center_horizontal" //里边控件的分布,水平居中
android:orientation="horizontal" >//排列方式:水平、垂直
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
</LinearLayout>
1.2 相对布局
RelativeLayout1.3 绝对布局
2.控件
- 2.1 图片
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"/><!-- 图片路径 -->
- 2.2 文本控件
<TextView
android:inputType="textPassword" <!-- 输入内容分类,密码、数字(number)、电话号码(phone)等等 -->
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
- 2.3 复选框
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
方法:
isChecked() //判断是否被选中,选中为true