Android-入门学习笔记-布局

  Android官方开发参考文档中国站点 查阅文档是必备机能!

  优达学城Android术语表

  Android材料设计指南

  XML(Extensible Markup Language)可扩展标记语言

  IDE( Integrated Development Environment )集成开发环境

  SDK(Software Development Kit) 软件库开发工具包

  JDK(Java Development Kit) Java开发工具包 

  API(Application Programming Interface)应用程序编程接口

  CamelCase 驼峰式拼写 

  view视图,是构建布局(layout)的基石

  dp( density independent pixel )密度独立像素,使视图在不同大小的设备中显示的相对大小一致

  触摸目标至少48dp

  sp(Scale Independent Pixels)规模独立像素,类似于dp使文本在不同大小设备显示的相对大小一致

  undo 撤销 redo 重做

  Typographic scale 版式尺寸

  Hardcode 硬编码,即自行给属性赋一确定数值

  文本视图

1 <TextView //<!--起始标签--> TextView:元素名称
2 android:text="Happy Birthday!"
3 android:background="@android:color/darker_gray"
4 android:layout_width="wrap_content"<!--wrap变形,wrap_content适应文本-->
5 android:layout_height="wrap_content" /> <!--自结束标签,带“斜杠”-->
//红色:元素属性,蓝色:属性值
//Android中可用“//”添加注释                                  

  独立起始标签、独立结束标签,方便查看子XML元素情况

 1 <LinearLayout    //线性布局,视图组,父视图,根视图
 2     android:orientation="vertical"
 3     android:layout_width="wrap_content"
 4     android:layout_height="wrap_content"> //与第1行左尖括号构成完整的独立起始标签。注意!此处无斜杠!
 5 
 6     <TextView  //子视图
 7         android:text="Guest List"
 8         android:layout_width="wrap_content"
 9         android:layout_height="wrap_content" />
10 
11     <TextView  //子视图
12         android:text="Kunal"
13         android:layout_width="wrap_content"
14         android:layout_height="wrap_content" />
15 
16 </LinearLayout> //独立结束标签

  图片视图

1 <ImageView
2     android:src="@drawable/cake"<!--source,@引用,资源类型/文件名-->
3   android:layout_width="400dp"
4   android:layout_height="500dp"
5   android:scaleType="centerCrop"/> //范围类型,Crop裁剪 android:scaleType属性

   Button 是对触摸敏感的 TextView,触摸会触发响应。  

  • 线性布局(LinearLayout)
  • 相对布局(RelativeLayout)
  • 约束布局(ConstraintLayout)参考链接

  Android布局的各种对齐问题

  命名空间,给某名称赋值,防止不同元素的同名属性相冲突。下面的代码中,即给android指定唯一URL。

 1 <LinearLayout
 2     xmlns:android="http://schemas.android.com/apk/res/android" //xmlns,namespace,命名空间,指定所有属性都属于android
 3     android:orientation="vertical"                 //方向垂直,水平“horizontal”
 4     android:layout_width="wrap_content"
 5     android:layout_height="wrap_content">
 6 
 7     <TextView
 8         android:text="Guest List"
 9         android:layout_width="wrap_content"
10         android:layout_height="wrap_content"
11         android:textSize="24sp"  />
12 
13     <TextView
14         android:text="Kunal"
15         android:layout_width="wrap_content"
16         android:layout_height="wrap_content"
17         android:textSize="24sp"  />
18 
19 </LinearLayout>
  •  布局权重(layout_weight),仅用于线性布局。详见:线性布局

   子视图初始宽度(高度)设为“0dp”,则父视图拥有全部剩余宽度(高度)。各子视图权重分别设为1、2、5,则各子试图分别占父视图宽度(高度)的1/8、1/4、5/8。

   子视图默认权重为“”0“,即不随父视图剩余可用空间而改变。

    

 1 <RelativeLayout
 2     xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent">
 5 
 6     <TextView
 7         android:id="@+id/lyla_text_view"    //创建id,注意格式 “+”,关于id属性的官方声明
 8         android:layout_width="wrap_content"
 9         android:layout_height="wrap_content"
10         android:layout_alignParentBottom="true" //align对齐,对齐父视图底部。若不设置,则默认对齐左上角。更多布局参数及相应xml属性的官方文档
11         android:layout_alignParentLeft="true"
12         android:textSize="24sp"
13         android:text="Lyla" />
14 
15     <TextView
16         android:id="@+id/me_text_view"
17         android:layout_width="wrap_content"
18         android:layout_height="wrap_content"
19         android:layout_alignParentBottom="true"
20         android:layout_toRightOf="@id/lyla_text_view"  //引用id,注意格式;置于**左边
21         android:textSize="24sp"
22         android:text="Me" />
23 
24     <TextView
25         android:id="@+id/natalie_text_view"
26         android:layout_width="wrap_content"
27         android:layout_height="wrap_content"
28         android:layout_above="@id/lyla_text_view"     //置于**上边,将此视图的下边缘定位在给定的锚点视图ID之上。
29         android:textSize="24sp"
30         android:text="Natalie" />
31 
32     <TextView
33         android:id="@+id/jennie_text_view"
34         android:layout_width="wrap_content"
35         android:layout_height="wrap_content"
36         android:layout_alignParentBottom="true"
37         android:layout_alignParentRight="true"
38         android:textSize="24sp"
39         android:text="Jennie" />
40 
41     <TextView
42         android:id="@+id/omoju_text_view"
43         android:layout_width="wrap_content"
44         android:layout_height="wrap_content"
45         android:layout_alignParentRight="true"
46         android:layout_above="@id/jennie_text_view"
47         android:textSize="24sp"
48         android:text="Omoju" />
49 
50     <TextView
51         android:id="@+id/amy_text_view"
52         android:layout_width="wrap_content"
53         android:layout_height="wrap_content"
54         android:layout_alignParentBottom="true"
55         android:layout_alignParentRight="true"
56         android:layout_above="@id/omoju_text_view"
57         android:textSize="24sp"
58         android:text="Amy" />
59 
60     <TextView
61         android:id="@+id/ben_text_view"
62         android:layout_width="wrap_content"
63         android:layout_height="wrap_content"
64         android:layout_alignParentTop="true"
65         android:layout_centerHorizontal="true"      //水平居中
66         android:textSize="24sp"
67         android:text="Ben" />
68 
69     <TextView
70         android:id="@+id/kunal_text_view"
71         android:layout_width="wrap_content"
72         android:layout_height="wrap_content"
73         android:layout_alignParentTop="true"
74         android:layout_toLeftOf="@id/ben_text_view"
75         android:textSize="24sp"
76         android:text="Kunal" />
77 
78     <TextView
79         android:id="@+id/kagure_text_view"
80         android:layout_width="wrap_content"
81         android:layout_height="wrap_content"
82         android:layout_alignParentTop="true"
83         android:layout_alignParentRight="true"
84         android:layout_toRightOf="@id/ben_text_view"
85         android:textSize="24sp"
86         android:text="Kagure" />
87 
88 </RelativeLayout>  

 

转载于:https://www.cnblogs.com/infocodez/p/7725937.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值