android基础学习<一>--->五大布局对象Framelayout,Linearlayout,Relativelayout,Tablelayout,AbsoluteLayout

Android中常见五种布局管理器——RelativeLayout、LinearLayout、FrameLayout、TableLayout、GridLayout 布局管理器 Android提供五种布局管理器: 1.相对布局管理器(RelativeLayout):通过相对定位的方式来控制组件的摆放位置。 2.线性布局管理器(LinearLayout):是指在水平或者垂直方向上依次摆放组件。 3.帧布局管理器(FrameLayout):没有任何定位方式,默认情况下,所有的组件都会摆放在容器的左上角,逐个覆盖。 4.表格布局管理器(TableLayout):使用表格的方式按行、列来摆放组件。 5.绝对布局管理器(AbsoluteLayout):通过绝对定位(x 阅读详情

今天学习android界面设计的layout,记下过程,相当于是做笔记了。

首先是Framelayout:

   Framelayout,字面意思上理解是“框架布局”。特点是 每个布局框架里头的元素都是在屏幕的左上角开始摆放,如果不止一个控件的话就相互重叠,后面的将前面的对象元素给覆盖掉。如果后面的对象是透明的话就可以看见前面的对象,不然后面的对象就会把前面的对象给覆盖。下面是例子:main.xml文件

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
  
<Button
 android:layout_height="wrap_content"
 android:layout_width="fill_parent"
 android:text="hello ,this is a Button!"
 />
<Button
 android:layout_width="125sp"
 android:layout_height="wrap_content"
 android:text="this is the second button"
 />
<RadioButton
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 />
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    android:textColor="#00aa00"
    />
</FrameLayout>



 

然后是Linearlayout:即相对布局。下面是main.xml文件根据xml布局文件就可以看出其用法。<!--     -->是xml文件的注释形式,这个比较重要,刚开始的时候还以为和.java文件里头的注释是一样的,闹了不少笑话。用//注释老是编译不过!悲剧了

<?xml version="1.0" encoding="utf-8"?>  
<!--   
   <LinearLayout>  
       线性版面配置,在这个标签中,所有元件都是按由上到下的排队排成的  
-->  
<LinearLayout   
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical"   
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent">  
   <!-- android:orientation="vertical" 表示竖直方式对齐  
        android:orientation="horizontal"表示水平方式对齐  
        android:layout_width="fill_parent"定义当前视图在屏幕上  
                     可以消费的宽度,fill_parent即填充整个屏幕。  
        android:layout_height="wrap_content":随着文字栏位的不同  
        而改变这个视图的宽度或者高度。有点自动设置框度或者高度的意思  
                
       layout_weight 用于给一个线性布局中的诸多视图的重要度赋值。  
     所有的视图都有一个layout_weight值,默认为零,意思是需要显示  
     多大的视图就占据多大的屏幕空 间。若赋一个高于零的值,则将父视  
     图中的可用空间分割,分割大小具体取决于每一个视图的layout_weight  
       值以及该值在当前屏幕布局的整体 layout_weight值和在其它视图屏幕布  
     局的layout_weight值中所占的比率而定。  
     举个例子:比如说我们在 水平方向上有一个文本标签和两个文本编辑元素。  
    该文本标签并无指定layout_weight值,所以它将占据需要提供的最少空间。  
    如果两个文本编辑元素每一个的layout_weight值都设置为1,则两者平分  
    在父视图布局剩余的宽度(因为我们声明这两者的重要度相等)。如果两个   
   文本编辑元素其中第一个的layout_weight值设置为1,而第二个的设置为2,  
   则剩余空间的三分之二分给第一个,三分之一分给第二个(数值越小,重要  
              度越高)。  
    -->  
    <LinearLayout  
    android:orientation="horizontal"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"  
    android:layout_weight="1">  
    <TextView  
        android:text="red"  
        android:gravity="center_horizontal"  
        android:background="#aa0000"  
        android:layout_width="wrap_content"  
        android:layout_height="fill_parent"  
       android:layout_weight="1"/>  
      
    <TextView  
        android:text="green"  
        android:gravity="center_horizontal"  
        android:background="#00aa00"  
        android:layout_width="wrap_content"  
        android:layout_height="fill_parent"  
        android:layout_weight="1"/>  
      
    <TextView  
        android:text="blue"  
        android:gravity="center_horizontal"  
        android:background="#0000aa"  
        android:layout_width="wrap_content"  
        android:layout_height="fill_parent"  
        android:layout_weight="1"/>  
      
    <TextView  
        android:text="yellow"  
        android:gravity="center_horizontal"  
        android:background="#aaaa00"  
        android:layout_width="wrap_content"  
        android:layout_height="fill_parent"  
        android:layout_weight="1"/>  
          
       </LinearLayout>  
      
    <LinearLayout  
    android:orientation="vertical"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"  
    android:layout_weight="2">  
      
    <TextView  
        android:text="row one"  
        android:textSize="15pt"  
        android:layout_width="fill_parent"  
        android:layout_height="wrap_content"  
        android:layout_weight="1"/>  
      
    <TextView  
        android:text="row two"  
        android:textSize="15pt"  
        android:layout_width="fill_parent"  
        android:layout_height="wrap_content"  
        android:layout_weight="1"/>  
      
    <TextView  
        android:text="row three"  
        android:textSize="15pt"  
        android:layout_width="fill_parent"  
        android:layout_height="wrap_content"  
        android:layout_weight="1"/>  
      
    <TextView  
        android:text="row four"  
        android:textSize="15pt"  
        android:layout_width="fill_parent"  
        android:layout_height="wrap_content"  
        android:layout_weight="1"/>  
          
    </LinearLayout>  
          
</LinearLayout> 

 

我是初学,在网上看到有大虾说在android开发中这个linearlayout是用得比较多的,拭目以待吧,看起来是要灵活一些哦。

 

下面是Relativelayout:相对布局。xml文件如下面所示。

main.xml文件代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
 android:id="@+id/label"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Type here:"
    android:textSize="15sp"
    />
<EditText
 android:id="@+id/entry"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:background="#ffffff"
 android:layout_below="@id/label"
 android:layout_marginBottom="10dp"
 android:text="在此输入文本..."
/>
<Button
 android:id="@+id/ok"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:text="OK"
 android:layout_alignParentRight="true"
 android:layout_below="@id/entry"
 android:layout_marginLeft="5dp"
 
/>
  <Button
 android:id="@+id/cancel"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_toLeftOf="@id/ok"
 android:layout_alignTop="@id/ok"
 android:text="Cancel"
/>
</RelativeLayout>


 

在相对布局中用得比较多的就我感觉就是相对屏幕位置左边呀,或者右边,顶部,等的位置。先记下来,以后在一步一步的研究,感觉这个在应用中还是蛮灵活的!

 

下面一个就是TableLayout,话不多说。现将xml文件和运行结果贴出来再说。

下面是xml文件:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:shrinkColumns="0,1,2"
    >
   <TableRow>
      <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="hello, i am button1"
            android:layout_column="0" 
             />
     <Button
             android:id="@+id/button2"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="hello, i am button2"
             android:layout_column="1" 
            />
   </TableRow>
        <TableRow>
  <Button
      android:id="@+id/button3"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="hello, i am button3"
      android:layout_column="1" 
    />
  <Button
      android:id="@+id/button4"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="hello, i am button4"
      android:layout_column="2" 
  />
  </TableRow>
      <TableRow>
     <Button
         android:id="@+id/button5"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="hello, i am button5"
         android:layout_column="2" 
          />
      </TableRow>
</TableLayout>


 

根据运行结果可以看出,每一个TableRow中的Button都是按照水平方向排列的,并且每个Button的位置可以用android:layout_column="2"来定义,其中参数表示位置,并且从0开始,如果是0就从屏幕的最左边开始排列,并且以此向后面排列。

 

最后就是AbsoluteLayout:绝对布局。此种布局形式是采用坐标的形式来排列activity中的对象。下面是xml文件:

 

main.xml:<?xml version="1.0" encoding="utf-8"?>
 <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     >
<EditText 
    android:text="input your name..."
     android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
/> 
<Button
 android:layout_x="370px"
 android:layout_y="65px"
 android:layout_width="100px"
 android:layout_height="wrap_content"
 android:text="OK"
/>
</AbsoluteLayout> 


运行结果截图:

 

以上就是android界面设计的5大布局哦!android学习必经之路!呵呵

 

Android基础教程(二)之五大布局对象---FrameLayout,LinearLayout ,AbsoluteLayout,RelativeLayout,TableLayout.  大家好,我们这一节讲一下Android对用五大布局对象,它们分别是FrameLayout(框架布局:不知道是不是这么翻译的),LinearLayout (线性布局),AbsoluteLayout(绝对布局),RelativeLayout(相对布局),TableLayout(表格布局). FrameLayout: FrameLayout是最简单的一个布局对象。它被定制为你屏幕上 阅读详情

相关推荐

Android五大布局

Android五大布局 Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦。组件按照布局的要求依次排列,就组成了用户所看见的界面。 Android的五大布局分别是LinearLayout(线性布局)、FrameLayout(单帧布局)、RelativeLayout(相对布局)、AbsoluteLayout(绝对布局,Android2.0中标注为已过期)和TableLayout(表格布局)。 android 线性布局(LinearLayout) 线性布局是程

Ashely_evina的博客 2226

Android —— LinearLayout属性集合(一)

在开发过程中,Android控件/控件属笥有好多都没有使用过,所以这里进行总结学习下 ^ ^ 一:LinearLayout 线性布局属性 1)baselineAligned :该属性默认为true,设为false后将会阻止该布局管理器与它的子元素基线对齐 根据图上的布局,将此属性设为false,然后运行后的结果如下: 将此属性去掉/设置为true,运行结果如...

沐沐的博客 1993

从DWS到设备树:MTK平台LK阶段GPIO初始化的隐秘路径与调试实战

本文深入探讨了MTK平台LK阶段GPIO初始化的完整流程,揭示了从DWS配置到设备树生成的隐秘转换路径。通过分析MT6768等平台的启动框架,提供了针对preloader到LK阶段GPIO初始化异常的实战调试方法与最佳实践,帮助开发者有效解决硬件与软件配置不匹配的常见问题。

h9j8k7l6m5n的博客 1003

android获得layout对象

方法一 final View view = LayoutInflater.from(context).inflate(R.layout.test, null); 方法二 LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view =

u012215825的专栏 2912

EnlightenGAN训练复现记录

记录EnlightenGAN过程中的问题和解决方式。提示:以下是本篇文章正文内容,下面案例可供参考。

L_27N113E的博客 3847

FPGA中的CMAC硬核与Interlaken硬核

CMAC硬核和Interlaken硬核是FPGA中两种重要的内置功能模块,它们分别在CNN推理和高带宽芯片到芯片接口方面发挥着关键作用。FPGA(Field Programmable Gate Array,现场可编程逻辑门阵列)中的CMAC硬核与Interlaken硬核是两种重要的内置功能模块,它们在FPGA设计中扮演着关键角色。需要注意的是,FPGA设计中的硬核选择不仅取决于硬核本身的性能,还需要考虑硬核与FPGA芯片其他部分的兼容性、功耗、成本等因素。Interlaken硬核。

weixin_41230430的博客 1481

Android LinearLayout的布局属性介绍

目录 1.位置属性 2.尺寸属性 3.id引用属性 4.特殊属性 1.位置属性 以下的属性值为true或者false Android:layout_alignWithParentIfMissing Android:layout_alignParentEnd         紧贴父元素结束位置结束 Android:layout_alignParentStart       紧贴着...

0729Liang 1万+

【Ablation Studies 理解】深度学习模型组件的对比实验/性能分析

Ablation Study 用于检测深度学习/机器学习模型中各部分构件对于整体的重要性。 可以理解为为:组件\tricks重要性测试、组件性能系统性分析、控制变量法、组件去除对比实验、性能敏感性测试、性能因子分析等 Ablation Studies 一些新颖的深度学习模型在论文中都会进行AblationStudy,这部分的主要意义在于系统性的移除模型中的各种组件/trick等因子或者是创新的...

TomRen 4588

Android布局控件之LinearLayout详解

  LinearLayout是线性布局控件,它包含的子控件将以横向或竖向的方式排列,按照相对位置来排列所有的widgets或者其他的containers,超过边界时,某些控件将缺失或消失。因此一个垂直列表的每一行只会有一个widget或者是container,而不管他们有多宽,而一个水平列表将会只有一个行高(高度为最高子控件的高度加上边框高度)。LinearLayout保持其所包含的widget或...

weixin_34185320的博客 1051

IIC协议常见误区解析:从时序图到实际波形(附逻辑分析仪实测)

本文深入解析IIC协议在实际应用中的常见误区,从理想时序图到逻辑分析仪实测波形的差异,揭示通信故障的根本原因。通过硬件设计优化、软件时序调优和高级调试技巧,帮助开发者有效规避IIC通信中的隐形陷阱,提升系统稳定性。

weixin_28738397的博客 370

保姆级教程:用Cadence Sigrity Power DC搞定HI3516A板卡电源压降仿真(含常见报错解决)

本文提供了一份详细的Cadence Sigrity Power DC直流压降仿真教程,特别针对HI3516A板卡设计。从环境准备、器件建模到仿真执行和结果解读,全面覆盖了电源完整性分析的关键步骤,并提供了常见报错的解决方案,帮助工程师快速掌握直流压降分析技术。

weixin_42569329的博客 322

Android五大布局:FrameLayout、LinearLayout、AbsoluteLayout、RelativeLayout和TableLayout

AndroidSDK 定义了多种布局方式以方便用户设计 UI。各种布局方式均为 ViewGroup 类的子类,结构如图 1 所示。本节将对 FrameLayout(单帧布局)、LinearLayout(线性布局)、AbsoluteLayout(绝对布局)、RelativeLayout(相对布局)和TableLayout(表格布局)进行简单的介绍。

一个IT人的技术成长历程。 3048

半小时搞定Yolov5安装配置及使用(详细过程)

Yolov51. 下载Yolov52. 安装Yolov5 在下载配置Yolov5前,先要安装好Anaconda环境,可参考之前博文:最新Anaconda3的安装配置及使用教程(详细过程) 1. 下载Yolov5 首先下载Yolov5源码: Yolov5 Github地址:https://github.com/ultralytics/yolov5 直接git clone到本地工作目录,等待下载完成: Yolov5代码目录架构: 2. 安装Yolov5 源码下完后,下面开始安装Yolov5所需模块,

HowieXue 薛永浩的博客 12万+

【Android】六大布局——LinearLayout、RelativeLayout、TableLayout、AbsoluteLayout、FrameLayout、GridLayout

Android中有四大组件六大布局,他们分别是: LinearLayout(线性布局) RelativeLayout(相对布局) TableLayout(表格布局) AbsoluteLayout(绝对布局) FrameLayout(帧布局) 以及有时被别人抛弃而总结成五大布局的GridLayout(网格布局)通常情况下,使用得比较多的是LinearLayout和RelativeLayou

yueh 897

【天气雷达】双偏振产品-差分传播相移KDP详解

双偏振产品-差分传播相移KDP详解。

珞瑜的博客 2661

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

android layout 多个布局文件,Android五大布局:FrameLayout、LinearLayout、AbsoluteLayout、RelativeLayout和TableLayout...

Android SDK 定义了多种布局方式以方便用户设计 UI。各种布局方式均为 ViewGroup 类的子类,结构如图 1 所示。图 1 Android SDK 布局方式结构图本节将对 FrameLayout(单帧布局)、LinearLayout(线性布局)、AbsoluteLayout(绝对布局)、RelativeLayout(相对布局)和TableLayout(表格布局)进行简单的介绍。F...

weixin_39622521的博客 590

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

阐述android中常用布局 及各自特点,Android五大布局介绍&属性设置大全

前言在进行Android开发中,常常需要用到各种布局来进行UI的绘制,今天我们就来讲下Android开发中最常用的五大布局介绍和相关属性的设置。目录Android五大布局介绍&属性设置.jpg一、布局介绍在Android中,共有五种布局方式,分别是:FrameLayout(框架布局)LinearLayout(线性布局)AbsoluteLayout(绝对布局)RelativeLayout(相...

weixin_32043233的博客 1万+

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Android布局:LinearLayout、FrameLayout和RelativeLayout,AbsoluteLayout

1、 LinearLayout  : 线性布局           .  LinearLayout按照垂直或者水平的顺序依次排列子元素,每一个子元素都位于前一个元素之后。如果是垂直排列,那么将是一个N行单列的结构,每一行只会有一个元素,而不论这个元素的宽度为多少;如果是水平排列,那么将是一个单行N列的结构。如果搭建两行两列的结构,通常的方式是先垂直排列两个元素,每一个元素里再包含一个Line

宝宝宝的博客 666

Android中的布局分为5种 分别是,Android五大布局介绍&属性设置大全

前言在进行Android开发中,常常需要用到各种布局来进行UI的绘制,今天我们就来讲下Android开发中最常用的五大布局介绍和相关属性的设置。目录Android五大布局介绍&属性设置.jpg一、布局介绍在Android中,共有五种布局方式,分别是:FrameLayout(框架布局)LinearLayout(线性布局)AbsoluteLayout(绝对布局)RelativeLayout(相...

weixin_39814126的博客 4048

Android五大布局——LinearLayout、RelativeLayout

Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦。组件按照布局的要求依次排列,就组成了用户所看见的界面。Android的五大布局分别是LinearLayout(线性布局)、FrameLayout(单帧布局)、RelativeLayout(相对布局)、AbsoluteLayout(绝对布局)和TableLayout(表格布局)。   Lin...

datao8756的博客 473

android五大布局的作用,Android五大布局与实际应用详解

Android总体有五大布局:线性布局(LiearLayout): 屏幕垂直或水平方向布局。帧布局(FrameLayout):控件从屏幕左上角开始布局。相对布局(RelativeLayout): 以其他控件为参照布局。绝对布局(AbsoluteLayout):以屏幕坐标布局。表格布局(TableLayout):按照行列方式布局。一、LinearLayout线性布局在开发中使用最多,具有垂直方向与水...

weixin_30768103的博客 2124

android五种布局特点

转载出处:http://dev.10086.cn/cmdn/wiki/index.php?doc-view-3633.html Android 五大布局   编辑文档 Android对用五大布局对象,它们分别是FrameLayout(框架布局),LinearLayout (线性布局),AbsoluteLayout(绝对布局),RelativeLayout(相对布局),T

android 开发专栏 1万+

Android的五大布局

学习安卓的五大布局

shan286的专栏 2061

浅谈Android五大布局—LinearLayout、FrameLayout、AbsoulteLayout、RelativeLayout和TalbeLayout。

Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦。组件按照布局的要求依次排列,就组成了用户所看见的界面。Android的五大布局分别是LinearLayout(线性布局)、FrameLayout(单帧布局)、RelativeLayout(相对布局)、AbsoluteLayout(绝对布局)和TableLayout(表格布局)。   Linear

Geek Nero 731
上一篇: Android中级教程之----Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)!
下一篇: 程序员从初级到中级10个秘诀
ivan21
博客等级 码龄16年 7粉丝 20原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值