iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >Android的四个基本布局
  • 201
分享到

Android的四个基本布局

2023-06-04 22:06:48 201人浏览 安东尼
摘要

在Android中有四种基本布局,可以放置很多控件的容器,按照一定的个一律调整控件的位置,从而编写出精美的界面1)线性布局:LinearLayout让我们来看一段代码<LinearLayout xmlns:android=&

Android中有四种基本布局,可以放置很多控件的容器,按照一定的个一律调整控件的位置,从而编写出精美的界面

1)线性布局:LinearLayout

让我们来看一段代码

<LinearLayout xmlns:android="Http://schemas,android.com/apk/res/android">android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"//android:layout_gravity="top"android:text="Button1"/><Buttonandroid:id="@+id/button2"android:layout_width="wrap_content"android:layout_height="wrap_content"//android:layout_gravity="center_vertical"android:text="Button2"/><Buttonandroid:id="@+id/button3"android:layout_width="wrap_content"android:layout_height="wrap_content"//android:layout_gravity="bottom"android:text="Button3"/><LinearLayout/>

其中orientation:vertical就是线性布局中的垂直布局

将其改为orientation:horizantal就是线性布局中的水平布局

注释符后的android:layout_gravity似乎看起来和android:gravity很像,实际上android:gravity是用来控制文字的,而android:layout_gravity是用来控制控件的,需要注意的是android:layout_gravity只能在垂直布局上用到,因为水平布局中的长度是不固定的,每添加一个就加长还有一个也很重要的属性:android:layout_weight,这是用来比例控制控件大小2)相对布局:RelativeLayout

<RelativeLayout xmlns:android="http://schemas,android.com/apk/res/android">android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><Buttonandroid:id="@+id/button1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentTop="true"android:text="Button1"/><Buttonandroid:id="@+id/button2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_alignParentTop="true"android:text="Button2"/><Buttonandroid:id="@+id/button3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:text="Button3"/><Buttonandroid:id="@+id/button4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_alignParentBottom="true"android:text="Button4"/><Buttonandroid:id="@+id/button5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:layout_alignParentBottom="true"android:text="Button5"/><RelativeLayout/>

这里用到的是layout_alignParentTop,layout_alignParentBottm,layout_alignParentLeft,layout_alignParentRight和layout_centerInParent,他们的意思显而易见

除此以外还有,layout_above,layout_below,layout_toLeftof,layout_toRightof

而layout_alignLeft,layout_alignRight,layout_alignTop,layout_alignBottom,则是利用边缘对齐的方式控制控件3)帧布局:FrameLayout它相比于其他两个布局就简单多了,它没有方便的定位方式,所有的控件都会显示在左上角4)百分比布局:PercentFrameLayout以及PercentRelativelayout其中有:app:layout_heightPercent,app:layout_widthPercent而在实际编程中,会发现一个问题,就是如果页面需要大量的重复控件,那么难道我们要一个个,一遍遍写吗?Android为我们提供了,引入布局的操作:<include layout="@layout/title"/>

--结束END--

本文标题: Android的四个基本布局

本文链接: https://www.lsjlt.com/news/240184.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Android的四个基本布局
    在Android中有四种基本布局,可以放置很多控件的容器,按照一定的个一律调整控件的位置,从而编写出精美的界面1)线性布局:LinearLayout让我们来看一段代码<LinearLayout xmlns:android=&...
    99+
    2023-06-04
  • Android的四种基本布局是什么
    Android有四种基本布局,分别是线性布局(LinearLayout)、相对布局(RelativeLayout)、帧布局(Fram...
    99+
    2023-08-11
    Android
  • Android的基本布局有哪些
    Android的基本布局有以下几种:1. 线性布局(LinearLayout):按照水平或垂直方向排列子视图,可以定义子视图之间的权...
    99+
    2023-08-18
    Android
  • Android studio基本布局有哪些
    本篇内容主要讲解“Android studio基本布局有哪些”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Android studio基本布局有哪些”吧!Android中常用...
    99+
    2023-07-05
  • Android 12 源码分析 —— 应用层 四(SystemUI的基本布局设计及其基本概念)
    Android 12 源码分析 —— 应用层 四(SystemUI的基本布局设计及其基本概念) 更新历史日期内容12023-9-11增加文中提及的渐变动画的效果图 在上两篇文章中,我们介绍System...
    99+
    2023-10-02
    SystemUI锁屏布局 SystemUI状态栏布局 SystemUIQS布局 QuickSettings布局 SystemUI通知布局
  • Android六大基本布局是什么
    Android中的六大基本布局是: 线性布局(LinearLayout):按照水平或垂直方向排列子视图。 相对布局(Rela...
    99+
    2023-10-26
    Android
  • HTML5基本布局是什么
    今天小编给大家分享一下HTML5基本布局是什么的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧...
    99+
    2024-04-02
  • Android四种常见布局方式示例教程
    目录一、线性布局LinearLayout有两种排序方式线性布局的权重二、相对布局RelativeLayout相对位置的取值三、网格布局GridLayout四、滚动视图ScrollVi...
    99+
    2024-04-02
  • Androidstudio六大基本布局详解
    目录Android中常用的布局方式有以下几种:(一)线性布局LinearLayout(二)相对布局RelativeLayout(三)表格布局TableLayout(四)帧布局Fram...
    99+
    2023-05-14
    Android studio六大布局 Android线性布局 Android相对布局
  • Android 的 FrameLayout (帧布局)
    本节引言 FrameLayout(帧布局)可以说是六大布局中最为简单的一个布局,这个布局直接在屏幕上开辟出一块空白的区域,当我们往里面添加控件的时候,会默认把他们放到这块区域的左上角,而这种布局方式却没有任何的定位方式,所以它应用的场景并不...
    99+
    2023-10-21
    android
  • flex布局基本语法有哪些
    这篇“flex布局基本语法有哪些”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“flex布局...
    99+
    2024-04-02
  • Android线性布局与相对布局的实现
    目录线性布局(LinearLayout)相对布局(RelativeLayout)总结线性布局(LinearLayout) 名字含义android:id设置一个id方便使用androi...
    99+
    2024-04-02
  • Android 的 TableLayout (表格布局)
    本节引言: 前面我们已经学习了平时实际开发中用得较多的线性布局(LinearLayout)与相对布局(RelativeLayout), 其实学完这两个基本就够用了,笔者在实际开发中用得比较多的也是这两个,当然作为一个好学的程序猿, 都是喜欢...
    99+
    2023-10-06
    android
  • 如何使用HTML创建一个基本的网格布局页面
    网格布局是一种常见且实用的页面布局方式,它能够以网格的形式将页面划分为多个区域,并且能够灵活地调整区域的大小和位置。在这篇文章中,我们将介绍如何使用HTML来创建一个基本的网格布局页面,并提供具体的代码示例供参考。首先,我们需要在HTML文...
    99+
    2023-10-21
    html 网格布局 创建
  • Android基础知识及线性布局介绍
    目录1.常见控件的基本属性1.1控件的可见性1.2控件的外边距1.3控件的内边距2.线性布局(Linear Layout)2.1示例:2.2微信界面实战3.总结1.常见控件的基本属性...
    99+
    2024-04-02
  • Android基础知识及线性布局的示例分析
    这篇文章主要介绍Android基础知识及线性布局的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!1.常见控件的基本属性android:id="@+id/button1":【设置控件id】a...
    99+
    2023-06-26
  • jQuery组件easyui基本布局实现代码
    以下是一个使用easyui实现基本布局的示例代码:Header...
    99+
    2023-08-16
    jQuery
  • jQuery组件easyui基本布局怎么实现
    jQuery EasyUI是一个基于jQuery的用户界面插件库,提供了丰富的UI组件和布局工具。下面是一种基本的布局实现方法:1....
    99+
    2023-08-16
    jQuery easyui
  • Android中的ConstraintLayout约束布局
    ConstraintLayout约束布局 ConstraintLayout有啥好处呢?可以减少布局层次,特别适合复杂的大型布局。可谓是集线性布局和相对布局于一身的荣誉布局。 使用 添加依赖 目前,An...
    99+
    2023-09-22
    android android studio
  • Android 基础知识4-2.10 GridLayout(网格布局)详解
    一、GridLayout(网格布局)概述         GridLayout 布局是 Android 4.0 以后引入的新布局,和 TableLayout(表格布局) 有点类似,不过它功能更多,也更加好用,最大的特点是放置的组件自动占据网...
    99+
    2023-09-02
    android android studio 学习
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作