1.控件布局的基本概念
所谓的控件布局方法,就是指控制控件在Activity的位置、大小、颜色以及其他控件样式属性的方法。
使用xml布局文件完成控件布局;
在java代码当中完成控件布局;
2.控件布局的种类
一类布局linear Layout 线形布局 最简单
relative Layout 相对布局 最常用
另一类
ListView 常用
GridView
3.距离单位 像素px dp sp
每英寸的像素个数dpi(dots per inch)=height的平方加+width的平方之和的平方根 再除以size
dp=dip 换算公式px=dp*(dpi/160)
在dpi为160的屏幕上:1dp=1px
sp单位通常用于字体的大小
当用修改手机显示字体时,sp会随之更给
通常在控件的长宽 使用 dp 使用字体的大小使用sp
4.控件的外边距与内边距
layout_margin 外边距
layout_marginTop上外外边距
layout_marginBotton 下外边距
layout_marginLeft 左边距
layout_marginRight 右边距
内边距
layout_padding 内边距
......<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textVeiw1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF0000"
android:text="第一个TextView控件" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00FF00"
android:text="第二个TextView" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="40dp"
android:background="#FF0000"
android:text="hello world" />
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="#00FF00"
android:paddingTop="30dp"
android:text="hello world" />
</LinearLayout>