第一次写博客,也是刚刚学到的安卓,说实话单词都做不到能完全背下来。
但是却感觉挺有意思,安卓,恩感觉用那个应用去写并不是特别的难。
让我感觉新手也可以拥有一个属于自己的设计。嘿嘿,我要开始说我第一次做的了,老师讲了讲,我们再做的。
恩,那个match说实话不明白啥意思,padding一系列的上下左右都表示离界面的距离,自己来设置。
学习的布局共分为六种,分别是相对布局、线性布局、表格布局、网格布局、帧布局、绝对布局。
还有Android在创建工程时默认为相对布局。
这两个例子是线性布局的。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_task1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:paddingRight="16dp"
android:paddingLeft="16dp"
android:orientation="vertical"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_task1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:paddingRight="16dp"
android:paddingLeft="16dp"
android:orientation="vertical"
线性布局为LinearLayout,有两种形式,一种是水平线性布局,另一种是垂直线性布局。
orientation属性取值就为 vertical 垂直和horizontal水平。现在需要的是垂直。
tools:context="cn.edu.bzu.a41lab_1.task1Activity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/colorAccent"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#f123"
android:layout_marginTop="10dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ff1234"
android:layout_marginTop="10dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#f0123456"
android:layout_marginTop="10dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#fff123"
android:layout_marginTop="10dp"
/>
</LinearLayout>
自己做的,手机拍的,还不能大于2M
background为背景颜色,可自己设,marginTop为与上一个下边界的距离。
这一个题做了一点,还有问题。与上一个不同的是这一个有一个是按钮Button。
原谅我刚刚学习安卓,才学了只一点点,以后的每一个都会是进步。哈哈
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_task2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:orientation="vertical"
tools:context="cn.edu.bzu.a41lab_1.task2Activity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="To"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subject" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Message"
android:layout_weight="1"
android:id="@+id/textView4" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:layout_marginStart="295dp"
android:layout_marginLeft="15dp"
android:id="@+id/button2" />
</LinearLayout>