基础篇1.6 Android Layout

Android View体系(八)从源码解析View的layout和draw流程 上一篇文章我们讲了View的measure的流程,接下来我们讲下View的layout和draw流程,如果你理解了View的measure的流程,那这篇文章自然就不在话下了。 阅读详情

基础篇1.6 Android Layout

1、  LinearLayout(线性布局)

(1)      应用举例:

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical"

    tools:context=".MainActivity">

    <!--

       android:id为控件指定相应的id

       android:text指定控件当中显示的文字,尽量使用@string

       android:grivity指定控件的基本位置

       android:textSize指定控件当中字体的大小

       android:background指定控件的背景颜色

       android:width控件的宽度

       android:heigth控件的高度

       android:padding*控件的内边框

       android:singleLine是否在一行中显示

       android:layout_*指定控件的高度和宽度布局

     -->

    <TextView

        android:id="@+id/firstText"

        android:text="第一行"

        android:gravity="center_vertical"

       android:textSize="35pt"

       android:background="#aa0000"

       android:layout_width="fill_parent"

       android:layout_height="wrap_content"

       android:paddingLeft="10dip"

       android:paddingTop="20dip"

       android:paddingRight="30dip"

       android:paddingBottom="10dip"

       android:layout_weight="1"

       android:singleLine="true"/>

    <TextView

        android:id="@+id/secondText"

        android:text="第二行"

        android:gravity="center_vertical"

        android:textSize="15pt"

        android:background="#0000aa"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:layout_weight="1"/>

</LinearLayout>

(2)      运行结果


2、  TableLayout(表格布局)

(1)      应用举例

<TableLayoutxmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:stretchColumns="1"

    tools:context=".MainActivity">

   <TableRow>

       <TextView

           android:text="row1_column1"

          android:padding="3dip"/>

       <TextView

          android:text="row1_column2"

          android:padding="3dip"

          android:gravity="center_horizontal"/>

       <TextView

          android:text="row1_column3"

          android:padding="3dip"

          android:gravity="right"/>

   </TableRow>

   <TableRow>

       <TextView

          android:text="row2_column1"

          android:padding="3dip"/>

       <TextView

          android:text="row2_column2"

          android:padding="3dip"

          android:gravity="right"/>

   </TableRow>

</TableLayout>

(2)      运行结果


3、  RelativeLayout(相对布局)

(1)      应用举例

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:padding="10px"

    tools:context=".MainActivity">

<!--

    android:layout_above 将该控件的底部置于给定ID的控件之上

    android:layout_below 将该控件的底部置于给定ID的控件之下

    android:layout_toLeftOf 将该控件的右边缘和给定ID控件的左边缘对齐

    android:layout_toRightOf 将该控件的右边缘和给定ID控件的左边缘对齐

   

    android:layout_alignBaseline 该控件的baseline和给定控件的baseline对齐

    android:layout_alignBottom 该控件的底部边缘与给定ID控件的底部边缘对齐

    android:layout_alignLeft 该控件的左边缘与给定ID控件的左边缘对齐

    android:layout_alignRight 该控件的右边缘与给定ID控件的右边缘对齐

   

    android:alignParentBottom 如果该值为true,则该控件的底部与父控件的底部对齐

    android:layout_alignParentLeft 如果该值为true,则该控件的左边与父控件的左边对齐

    android:layout_alignParentRight 如果该值为true,则该控件的右边与父控件的右边对齐

    android:layout_alignParentTop 如果该值为true,则该控件的顶部与父控件的顶部对齐

   

    android:layout_centerHorizontal 如果为true,该控件将置于水平方向的中央

    android:layout_centerInParent 如果为true,该控件将置于父控件的中央

    android:layout_centerVertical 如果为true,该控件将置于垂直方向中央

 -->

<TextView

    android:id="@+id/myTextView"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="Please Input:"/>

<EditText

    android:id="@+id/myEditText"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:layout_below="@+id/myTextView"/>

<Button

    android:id="@+id/myButton01"

    android:layout_below="@+id/myEditText"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:layout_alignParentRight="true"

    android:layout_marginLeft="20px"

    android:text="OK"/>

<Button

    android:id="@+id/myButton02"

    android:layout_toLeftOf="@+id/myButton01"

    android:layout_alignTop="@+id/myButton01"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="Cancel"/>

</RelativeLayout>

(2)      运行结果


Android性能优化--Layout优化篇 Layout是Android程序的用户体验的最为直接的关键部分。本文将讲述如何使Layout占用尽可能少的内存,尽可能流畅。 一. 优化Layout层级Android SDK中有个工具Hierarchy Viewer,位于<sdk>/tool/目录下,用来分析应用程序Layout,快速定位Layout的性能瓶颈。 (1)使用RelativeLayout代替LinearLayout<?xml vers 阅读详情

相关推荐

查看Android physical memory layout和virtual memory layout

抓取Android kernel开机log: 1. physical memory layout: 在log中搜索“PHY layout”: [ 0.000000] -(0)[0:swapper][PHY layout]atf-reserved-memory@44600000 : 0x44600000 - 0x4460ffff (0x10000) [ 0.000000]

laughing_zou的专栏 1489

【Android】相对布局(RelativeLayout)最全解析

相对布局(RelativeLayout)是一种根据父容器和兄弟控件作为参照来确定控件位置的布局方式。使用相对布局,需要将布局节点改成

lucashu的博客 6万+

【深度解析】信息素养提升实践活动(附:历年获奖作品分析)

全国师生信息素养提升实践活动是由教育部教育技术与资源发展中心(中央电化教育馆)主办,面向全国师生的一项信息化交流展示活动。

m0_74417957的博客 9646

[Android布局]Relativelayout内部控件使用layout_toLeftOf或layout_toRightOf出错(会造成不能解析R文件)

问题描述 text属性为"18" 的TextView控件需要在ImageView左边,于是我就按从左到右的顺序写了控件布局,然后在TextView中加入layout_toLeftOf="@id/age_more"属性值,这导致R文件解析出错。 原因 在定义ImageView的id之前使用了该id,即"@id/age_more",会使编译程序不能找到该id。 解决办法 将id定义移动到使用之前,因为...

qq_40055714的博客 1045

动态数据脱敏技术分析

在当前国内信息安全热潮中,数据脱敏作为数据安全的重要一环得到了业界的认可与重视。早在2012年,数据脱敏首次作为一个单独的魔力象限由Gartner发布,Gartner在2014年又提出了:按照数据使用场景,将数据脱敏分为静态数据脱敏(Static data masking-SDM )与动态数据脱敏(Dynamic data masking-DDM )。 可能有人望文生义,认为动态数据脱敏一定比静态数据脱敏高级。非也非也,静态or动态,取决于脱敏的使用场景,主要是以使用场景为由来选择合适的数据脱敏的模式。 本

美创科技的博客 4667

DVWA靶场实战:手把手教你绕过文件上传限制,用蚁剑连接一句话木马

本文详细介绍了在DVWA靶场中如何绕过文件上传限制并利用蚁剑连接一句话木马的实战技巧。通过分析文件上传漏洞原理、创建一句话木马、使用Burp Suite拦截修改请求以及配置蚁剑连接WebShell的全过程,帮助安全研究人员深入理解Web安全防护与攻击技术。

weixin_30335575的博客 90

关于Android Studio使用layout_toLeftOf这种相对布局属性时报错 , 找不到id和R文件的错误

在编程时本来运行的好好的代码 , 在布局中增加了相对布局 , 然后使用了 android:layout_toLeftOf="@id/singer_music_playing_home"  这行代码 , 然后一运行就出现错误 进而发现R文件也离奇失踪了 , 看了网上的教程 , 大牛们的方法clean project和rebuild都不管用 , 也不是设置了禁止导入R文件 , 网上的解决方案

yjs1043014961的博客 2440

基于迁移学习的花卉识别系统

本研究采用了预训练的经典深度学习模型,包括ResNet、AlexNet和VGG,通过微调的方式在Oxford-102数据集和一个自制花卉数据集上进行训练,并对图像进行了多种数据增强操作,以提高模型的泛化能力,致力于实现花卉的高效分类。

m0_71146337的博客 2375

Android布局:LinearLayout、FrameLayout和RelativeLayout,AbsoluteLayout

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

宝宝宝的博客 666

13、无人机网络安全攻击检测:入侵检测系统综述

本文综述了无人机网络(FANETs)中的网络安全攻击与入侵检测系统(IDS)研究进展。文章介绍了无人机网络的架构设计、路由协议分类及移动模型,重点分析了DoS、DDoS、病毒蠕虫和零日攻击等常见安全威胁,并系统梳理了网络型、主机型、签名型、异常型、混合型等多种IDS的技术原理与应用。通过对比不同攻击类型及其检测机制,提出了综合使用多类IDS、更新签名库、优化路由、加强加密和建立应急响应等安全防护建议。同时展望了人工智能、量子安全和融合安全架构等未来发展趋势,旨在为提升无人机网络的安全性提供全面的技术参考。

wasm7browser的博客 162

基于高光谱的物质反演与分类 — 技术文章(原理详解 + 深度代码实现)

高光谱遥感 / 近场光谱采集产生逐像素上百波段的光谱曲线,是物质识别与定量反演(abundance / composition estimation)和语义分类(landcover / material class)的一把利器。本文第一部分对常用模型(线性混合模型、非线性辐射传输、稀疏反演、降维与特征选择、分类器/神经网络)进行数学推导与理论分析;第二部分给出两套完整实现:A. 基于 LMM 的约束最小二乘 / 稀疏反演流水线(含端到端评估);

VectorShift的博客 219

android 相对定位布局方向

大体分为三大 类: 第一类:两个组件之间的定位,(A在B的上面,下面,还是左面或右面)         android:layout_above=""         android:layout_below=""         android:layout_toLeftOf=""         android:layout_toRightOf=""   第二类:两个组件之间的对

luckyjda — —you can , I can . you can't , I can ! 1438

SAP MM ME21N保存前检查增强

想在ME21N保存前做一些数据检查, 可以做一个增强功能,  运行 CMOD 新增,   增强接口 输入 MM06E005  (  EXIT_SAPMM06E_012 ) ,在 NCLUDE ZXM06U43 .  里写代码功能。  例子如下: *&---------------------------------------------------------------------*

heng0757的专栏 1万+

Android基础Layout介绍

一、Common Layout和Adapter介绍 RelativeLayout (相对布局) LinearLayout (线性布局) GridLayout (网格布局) FrameLayout (帧布局,一层一层的布局) 每种Layout有不同的使用场景和功能,其中相对布局和线性布局最为常用。 二、Common Layout优化 优化目的: 提高运行效率,提

aldenlee的博客 658

CMOS图像传感器——Remosaic技术

对remosaic技术进行了介绍

沧海一升的博客 9581

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

【Android基础篇】使用<include>标签分割Layout

在Android的Layout中有一个标签用于引用其它的Layout界面设计文件,类似于javascript的script引用,我们可以用这个标签实现对大型layout界面文件的分割,提高可读性和可维护性。下面是一个简单的示例:fragment_main.xml<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/andr

zgljl2012的专栏 2770

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

android layout_width 属性,android:layout_weight属性详解

在android开发中LinearLayout很常用,LinearLayout的内控件的android:layout_weight在某些场景显得非常重要,比如我们需要按比例显示。android并没用提供table这样的控件,虽然有TableLayout,但是它并非是我们想象中的像html里面的table那么好用,我们常用ListView实现table的效果,但是列对齐确比较麻烦,现在用Linear...

weixin_42299778的博客 8005

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Android基础篇 屏幕横竖屏切换(layout-land)下篇

默认情况下Activity进行屏幕旋转会自动进行onDestroy并重新onCreate 一、非默认情况下 在AndroidManifest.xml的Activity中配置 <activity android:name=".ui.activity.XXXXXActivity" android:launchMode="singleTask" android:screenOrientation="portrait" .

圈池 6032

Android基础Layout_weigth

常见属性 1、情况一 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent">

weichaoya的博客 185

android xml layout,Android Layout XML属性

Layout对于迅速的搭建界面和提高界面在不同分辨率的屏幕上的适应性具有很大的作用。这里简要介绍Android的Layout和研究一下它的实现。Android有Layout:FrameLayout,LinearLayout,TableLayout,RelativeLayout,AbsoluteLayout。放入Layout中进行排布的View的XML属性:1.几种Layout中Item所共有的XM...

weixin_39623050的博客 422

Android ConstraintLayout属性简介(一、基础篇)

Android ConstraintLayout属性简介(一) 本篇文章介绍ConstraintLayout下面几个最基本的属性: layout_constraintLeft_toLeftOf layout_constraintLeft_toRightOf layout_constraintRight_toLeftOf layout_constraintRight_toRightOf layout_constraintTop_toTopOf layout_constraintTop_toBottomOf

海纳百川Android的博客 7851

关于Android相对布局中的四个属性:layout_alignTop,layout_alignBottom,layout_above,layout_below的分析

前几天想要实现仿微信的界面,在使用相对布局时用到

lsyAndroid的专栏--解决实际开发中自己遇到的问题 4万+

Android View 绘制流程之二:layout布局

Android View 绘制流程之二:layout布局一.layout整体流程二.常见onLayout实现1.FrameLayout的onLayout2.LinearLayout的onLayout3.RelativeLayout的onLayout layout(int left,int top,int right,int bottom)方法是View测绘系统的第二步,布局过程,是在measure...

依生依世 722

安卓开发技巧一:深入理解Android布局中Layout_weight的属性

今天开始将要为大家介绍一些安卓开发过程将要用到的一些技巧,这些技巧全部来自网络搜集,或者自己在企业做项目的时候总结出来的,利用这些技巧将会对我们开发带来非常方便的便捷性。 先来记录一下这一段时间的技巧目录,方便大家以后方便查阅(大概有不到三十种的技巧总结,大概每周分享两个技巧,笔者将尽可能写的详细,以及提供实例源码): 安卓开发技巧一:深入理解Android布局中Layout_weight的属

momocsdn 5512

安卓新手之路——关于layout一些属性的整理

常见的如id,text之类的属性就不多说了,下面详细介绍自己以及新手需要记忆的。 1.android:gravity 指定View组件的对齐方式,比如说居中,居右等位置。这里指的是控件中的文本位置并不是控件本身。 2. android:layout_gravity ...

chengqianghong1082的博客 205

android layout_weight 百分比,Android百分比布局之layout_weight属性

如果转载,请注明出处:http://blog.csdn.net/wangdejun/article/details/42739983 谢谢。在Android中对控件布局指定尺寸时,一般有两种方式:一种设定为自适应布局,即match_parent(fill_parent)或者wrap_content,通过根据父布局大小或者自己内容来产生一个动态尺寸;另外一种通过指定一个具体数值的方式定义成固定...

weixin_28327051的博客 2646
上一篇: Eclipse下常用插件安装
下一篇: 基础篇1.7 SQLite
AI布道师-wang
博客等级 码龄19年 79粉丝 143原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值