Android入门第二篇之LinearLayout、AbsoluteLayout

简介:

Android 的UI 布局都以Layout 作为容器,在上面按照规定排列控件,这方面跟JAVA 的Swing 和LWUIT 很像。控件跟Layout 有很多属性是一样的,可以在Properties 里面修改,跟.NET/Delphi 等RAD 类似,其中最常用的属性有以下这些:

id="@+id/edtInput",ID 是连接UI 与代码的桥梁

Gravity= "center" ,Layout 中的控件居中

 

layout_width="fill_parent" ,自动填充至屏幕宽度,layout_height 同理

 

layout_width="wrap_content" ,自动填充为控件大小,layout_height 同理

 

LinearLayout ,在入门第一篇所用的Layout 就是LinearLayout ,它的理解很简单:在LinearLayout 里面的控件,按照水平或者垂直排列:
orientation="horizontal" :水平排列;orientation=" vertical" :垂直排列 
当LinearLayout 是horizontal ,并且里面的控件使用了layout_width="fill_parent" ,第二组控件会挡在屏幕的右边,那也就是看不到了。。。

AbsoluteLayout ,是一个按照绝对坐标定义的布局,由于使用绝对坐标去定位控件,因此要实现自适应界面时,应尽少使用 AbsoluteLayout 。 AbsoluteLayout 里面的控件都以layout_x 、layout_y 来定义其位置:

 

上图中的TextView01的X坐标为10px,Y坐标为10px:

 
  1. <AbsoluteLayout android:id="@+id/AbsoluteLayout01" android:layout_height="wrap_content" android:layout_width="fill_parent" >       
  2. <TextView android:text="TextView01" android:id="@+id/TextView01" android:layout_height="wrap_content" android:layout_y="10px" android:layout_width="wrap_content" android:layout_x="110px">       
  3. </TextView>       
  4. </AbsoluteLayout>  
 
  1. <AbsoluteLayout android:id="@+id/AbsoluteLayout01" android:layout_height="wrap_content" android:layout_width="fill_parent" >     
  2. <TextView android:text="TextView01" android:id="@+id/TextView01" android:layout_height="wrap_content" android:layout_y="10px" android:layout_width="wrap_content" android:layout_x="110px">     
  3. </TextView>     
  4. </AbsoluteLayout>    

 


     本文转自xyz_lmn51CTO博客,原文链接:http://blog.51cto.com/xyzlmn/819882,如需转载请自行联系原作者


相关文章
|
1月前
|
XML Android开发 数据格式
android点击FrameLayout、LinearLayout等父布局没响应的原因以及解决方案
android点击FrameLayout、LinearLayout等父布局没响应的原因以及解决方案
32 2
|
3天前
|
XML Android开发 数据格式
Android五大布局对象---FrameLayout,LinearLayout ,Absolute
Android五大布局对象---FrameLayout,LinearLayout ,Absolute
|
3天前
|
Android开发
Android游戏引擎AndEngine入门资料
Android游戏引擎AndEngine入门资料
|
3天前
|
Java Android开发
android AsyncTask入门
android AsyncTask入门
|
4天前
|
Java API 开发工具
java与Android开发入门指南
java与Android开发入门指南
11 0
|
29天前
|
XML 存储 Java
安卓应用开发入门:构建您的第一个移动应用
【4月更文挑战第13天】本文引导读者入门安卓应用开发,首先介绍设置开发环境,包括安装JDK和Android Studio。接着,通过Android Studio创建第一个项目,解析项目结构,重点讲解`AndroidManifest.xml`和`activity_main.xml`。然后,设计一个显示&quot;Hello World!&quot;的布局,并在`MainActivity.java`中编写相应逻辑。最后,运行并调试应用,鼓励读者继续学习安卓开发的更多知识,提升技能。
|
2月前
|
测试技术 API 调度
【Android 从入门到出门】第七章:开始使用WorkManager
【Android 从入门到出门】第七章:开始使用WorkManager
20 3
【Android 从入门到出门】第七章:开始使用WorkManager
|
2月前
|
存储 Android开发 C++
【Android 从入门到出门】第五章:使用DataStore存储数据和测试
【Android 从入门到出门】第五章:使用DataStore存储数据和测试
48 3
|
2月前
|
Android开发
【Android 从入门到出门】第四章:现代Android开发中的导航
【Android 从入门到出门】第四章:现代Android开发中的导航
23 2
【Android 从入门到出门】第四章:现代Android开发中的导航
|
2月前
|
XML API Android开发
【Android 从入门到出门】第三章:使用Hilt处理Jetpack Compose UI状态
【Android 从入门到出门】第三章:使用Hilt处理Jetpack Compose UI状态
33 4