布局 (第一集) margin padding gravity layout_gravity
五种布局:FrameLayout(框架布局)、LinearLayout(线性布局)、RelativeLayout(相对布局)、TableLayout(表格布局)、AbsoluteLayout(绝对布局)。
可视化控件均继承android.view.View
创建视图的两种方式:一、XML配置View的相关属性,后装载。二、完全用java代码创建View。
Xml,必须包含在res/layout目录。必须以.xml文件名结束,必须符合java规范,命名空间系统自动生成。标签指定的id为:android:id="@+id/标签名称",该标记保存在R文件中。
若要使用xml布局文件,需要在oncreate方法中使用setContentView,findViewById方法要在这儿之后使用。
长度单位
一、PX:象素,屏幕实际尺寸 dp:屏幕的物理尺寸,一英寸的、1/72. sp:与刻度无关,与dp 相似,可根据字体大小缩放。
Layout_margin属性
(xml报错)
一、project--clean
二、http://tieba.baidu.com/p/2330946468 、、、Window->Preferences->General->Editors->Text Editors->Show whitespace characters
真机运行 命令行adb devices 右键文件run application
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="40dp"
android:layout_marginBottom="100dp"
android:layout_marginRight="60dp"
android:layout_height="wrap_content"
android:text="测试按钮一" />
成果及layout_margin、layout_padding说明见说说2015-12-15
默认为内容包裹
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="20sp"
android:paddingTop="5sp"
android:text="测试按钮一"
android:gravity text相对于按钮的位置
android:layout gravity 按钮相对于整个窗口
其他更为复杂的区别
http://www.cnblogs.com/xiaoQLu/archive/2012/10/22/2733631.html
第二集 线性布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFFFFF" >
<LinearLayout
android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content">
<EditText
android:id="@+id/msg" android:layout_width="match_parent" android:layout_height="wrap_content"
></EditText>
</LinearLayout>
<!--布局可以嵌套布局 -->
<LinearLayout
android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content">
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="mc" android:layout_weight="1"/>
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="m+" android:layout_weight="1"/>
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="m-" android:layout_weight="1"/>
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="mr" android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content">
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="C" android:layout_weight="1"/>
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="+/-" android:layout_weight="1"/>
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="/" android:layout_weight="1"/>
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="*" android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content">
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="7" android:layout_weight="1"/>
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="8" android:layout_weight="1"/>
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="9" android:layout_weight="1"/>
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="-" android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content">
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="4" android:layout_weight="1"/>
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="5" android:layout_weight="1"/>
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="6" android:layout_weight="1"/>
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="+" android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content">
<LinearLayout
android:layout_weight="3"
android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content" >
<LinearLayout
android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content">
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="1" android:layout_weight="1"/>
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="2" android:layout_weight="1"/>
<Button
android:layout_width="match_parent" android:layout_height="wrap_content" android:text="3" android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content">
<Button
android:layout_width="0px" android:layout_height="wrap_content" android:text="0" android:layout_weight="2"/>
<Button
android:layout_width="0px" android:layout_height="wrap_content" android:text="." android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="match_parent">
<Button
android:layout_width="match_parent" android:layout_height="match_parent" android:text="=" android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
第三集 框架布局(framelayout)
层叠图片
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/a"
android:layout_gravity="center"
/>
<ImageView
android:layout_width="63dp"
android:layout_height="46dp"
android:background="@drawable/b"
android:layout_gravity="center"
android:layout_marginTop="80dp"
/>
<ImageView
android:layout_width="85dp"
android:layout_height="85dp"
android:background="@drawable/c"
android:layout_gravity="center"
android:layout_marginBottom="80dp"
/>
</FrameLayout>
第四集 相对布局(realativelayout)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1"
android:textSize="16dp" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2"
android:textSize="16dp"
android:layout_toRightOf="@id/button1"
android:layout_below="@id/button1" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button3"
android:textSize="16dp"
android:layout_toLeftOf="@id/button2"
android:layout_below="@id/button2"
/>
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button4"
android:textSize="16dp"
android:layout_toRightOf="@id/button2"
android:layout_above="@id/button2" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button5"
android:textSize="16dp"
android:layout_toRightOf="@id/button2"
android:layout_below="@id/button2" />
</RelativeLayout>
第五集 表格布局(tablelayout)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableLayout
android:id="@+id/tablelayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:stretchColumns="0" >
<TableRow
android:id="@+id/tablerow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#fd8d8d"
android:textColor="#000000"
android:padding="4px"
android:text="表格布局的使用"
android:layout_centerInParent="true">
</TextView>
</TableRow>
</TableLayout>
<TableLayout
android:id="@+id/mytablelayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="0,1,2,3">
<TableRow
android:id="@+id/tablerow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button1"
></Button>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button2"
></Button>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button3"
></Button>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button4"
></Button>
</TableRow>
</TableLayout>
<TableLayout
android:id="@+id/tablelayout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0">
<TableRow android:id="@+id/tablerow3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<EditText
android:text="查询"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/textview"
/>
</TableRow>
</TableLayout>
</LinearLayout>

浙公网安备 33010602011771号