Android客户端|青训营笔记

101 阅读1分钟

Android客户端|青训营笔记

这是我参加「 第四届青训营 -客户端&Android基础场 」笔记活动第1篇笔记

什么是Android UI?

UI:User Interface Android系统是图形用户界面操作系统 UI界面由多个不同功能的UI组件构成 Android SDK提供了大量的UI组件

image.png

image.png

UI组件间关系

图3 view和viewgroup的关系image.pngviewgroup可以嵌套view,view不能包含view,viewgroup既能包含view,又能包含viewgroup

image.png图4 部分view的继承关系

image.png

image.png

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="16dp" android:paddingRight="16dp" android:orientation="vertical" > <EditText android:layout_width="match_parent" android:layout_height="wrap_content" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" /> <EditText android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="top" /> <Button android:layout_width="100dp" android:layout_height="wrap_content" android:layout_gravity="right" /> </LinearLayout>

image.pngmatch_parent等宽但有间距是因为LinearLayout设置了padding,排列方向是垂直方向orientation="vertical"排列方向是垂直方向,layout_height="0dp"本来应该没有高度,但设置了权重为1,其余EditText默认是0,gravity="top",内容是左上角位置,Button的layout_gravity="right"相对在父容器的右边。

image.pngrelativeLayout是根据相对位置定位的 RelativeLayout示例

`

<EditText
    android:id="@+id/name"        
    android:layout_width="match_parent"   
    android:layout_height="wrap_content" />  

 <Spinner        
    android:id="@+id/dates"        
    android:layout_width="0dp"    android:layout_height="wrap_content"  
    android:layout_below="@id/name"    
    android:layout_alignParentLeft="true"       
    android:layout_toLeftOf="@+id/times" />    

<Spinner        
    android:id="@id/times"        
    android:layout_width="96dp"    android:layout_height="wrap_content"   
    android:layout_below="@id/name" 
    android:layout_alignParentRight="true" />    

<Button        
    android:layout_width="96dp"    android:layout_height="wrap_content"   
    android:layout_below="@id/times" 
    android:layout_alignParentRight="true"  />
复制代码

`

image.png

image.png这是一个层级布局

image.png

image.png

image.png

image.png

布局加载

1.编写布局文件 2.注册Manifast 3.设置布局文件 布局解析-LayoutInflater LayoutInflater做了什么? LayoutInflater解析了XML文件,并根据XML文件生成了view实例,并将view实例添加到ViewGroup中。 XLM中的View是如何生成实现的? 根据XML中的view类名来找相应view,并将XML中的描述属性解析为AttributeSet,并作为第二个参数传给View构造器。