UdacityAS(1)–生日贺卡
此为在优达学城上的视频学习笔记(www.udacity.com),1.1表示的是入门级难度的第一部分——打造布局。
这是对于xml的再认识,所以不会有之前系统的笔记介绍,但是都是自己的学习心得。
视图及视图组
视图组就是ViewGroup,它本身就是一个容器,当然也是一个视图,在视图组中可以有ImageView,TextView等等视图作为其子视图。
线性布局与相对布局
线性布局是LinearLayout,相对布局是RelativeLayout,在进行用户界面设计时可以根据不同的需要进行合理选择。
线性布局可以设置水平和垂直,一般对视图的整体架构上有影响,而相对布局则可以设置其在不同的位置。
内边框和外边框
内边框是相对于当前视图的边框,使用的是margin,而外边框则是相对于父视图的边框,使用的是padding。
自学方法
有几个很好的渠道,一是关注AS的官方博客,二是在github上研究源码,在这个过程中难免会遇到很多的问题,这时候可以利用google进行定向搜索了,在需要了解的例如xml属性之后加入Android关键词,然后进入developer.android.com查找官方文档的属性值(这时可以使用谷歌浏览器的find功能)
程序实例——birthdayCard
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.dell1.birthdaycard.MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/birthdayCard"
//使用centerCrop是将整张图片长宽均等放大到合理位置
android:scaleType="centerCrop"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mr.Been: "
android:textSize="32sp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:textStyle="italic"
android:fontFamily="sans-serif-condensed"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:text="From William"
android:textSize="32sp"
android:textStyle="italic"
android:fontFamily="sans-serif-condensed"/>
</RelativeLayout>
代码简介清晰,在此就不做过多的介绍了,呈现的xml页面是这样的形式: