用android LinearLayout和RelativeLayout实现精确布局(转)
先明确几个概念的区别:
padding margin都是边距的含义,关键问题得明白是什么相对什么的边距.
padding是控件的内容相对控件的边缘的边距.
margin是控件边缘相对父控件的边距.
android:gravity 属性是对该view 内容的限定.比如一个button 上面的text. 你可以设置该text 在view的靠左,靠右等位置.该属性就干了这个.
android:layout_gravity是用来设置该view中的子view相对于父view的位置.比如一个button 在linearlayout里,你想把该button放在靠左,靠右等位置就可以在linearlayout中通过该属性设置.
下面看布局文件及效果图
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal" android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:gravity="center_vertical">
- <ImageView android:id="@+id/ivLogo" android:layout_width="50dp"
- android:layout_height="50dp" android:src="@drawable/icon"
- android:paddingLeft="5dp" />
- <RelativeLayout android:id="@+id/rl_name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:gravity="right"
- android:padding="10dp">
- <TextView android:id="@+id/tvApplicationName"
- android:layout_width="wrap_content" android:layout_height="wrap_content"
- android:textSize="16dp" />
- </RelativeLayout>
- <RelativeLayout android:id="@+id/rl_score"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:gravity="right"
- android:padding="10dp">
- <TextView android:id="@+id/tvRating" android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:text="5.0" />
- <RatingBar android:id="@+id/ratingbar" android:layout_width="wrap_content"
- android:layout_height="wrap_content" android:numStars="5"
- style="?android:attr/ratingBarStyleSmall" android:layout_below="@id/tvRating" />
- </RelativeLayout>
- </LinearLayout>
上面的布局文件是一个ListView中的list_item布局,在一个ListView中显示所有的APK资源,每个资源项显示图标,名称及评分。在listItem的最外层LinearLayout中加android:gravity="center_vertical",设定内容垂直居中显示。在id为rl_score的RelativeLayout中设定android:layout_width="fill_parent"来填充剩余空间;android:gravity="right"设定内容相对于rl_score右对齐;android:padding="10dp"设定RelativeLayout中的内容相对RelativeLayout的边缘的边距为10dp。
这个布局虽然简单,但却是经常用到的。
引用请注明出处:http://zhangkun716717-126-com.iteye.com/
http://zhangkun716717-126-com.iteye.com/blog/869039
用android LinearLayout和RelativeLayout实现精确布局(转)的更多相关文章
- android LinearLayout和RelativeLayout实现精确布局
先明确几个概念的区别: padding margin:都是边距的含义,关键问题得明白是什么相对什么的边距padding:是控件的内容相对控件的边缘的边距. margin :是控件边缘相对父空间的边距 ...
- [转]用android LinearLayout和RelativeLayout实现精确布局
先明确几个概念的区别: padding margin都是边距的含义,关键问题得明白是什么相对什么的边距. padding是控件的内容相对控件的边缘的边距. margin是控件边缘相对父控件的边距. a ...
- Android开发——LinearLayout和RelativeLayout的性能对比
0. 前言 我们都知道新建一个Android项目自动生成的Xml布局文件的根节点默认是RelativeLayout,这不是IDE默认设置,而是由android-sdk\tools\templates\ ...
- 【Android】7.5 RelativeLayout(相对布局)
分类:C#.Android.VS2015: 创建日期:2016-02-11 一.简介 RelativeLayout是一种相对布局,容器中子元素的位置是相对于其前一个元素或者其他元素的位置来计算的,或者 ...
- Android五大布局详解——RelativeLayout(相对布局)
RelativeLayout 接着上一篇,本篇我将介绍RelativeLayout(相对布局)的一些知识点. RelativeLayout 这是一个非常常用的布局,相比于上节所学到的LinearLay ...
- Android的学习第六章(布局二--RelativeLayout)
今天我们来说一下Android布局中的Relativelayout布局(相对布局) 根据英译过来意思是相对布局,很容易理解,这一样布局使用的是元素与元素之间的微调做到布局的 含义:通过元素与元素之间的 ...
- Android的学习第六章(布局一LinearLayout)
今天我们来说一下Android五大布局-LinearLayout布局(线性布局) 含义:线性布局,顾名思义,指的是整个Android布局中的控件摆放方式是以线性的方式摆放的, 主要作用:主要对整个界面 ...
- 关于android LinearLayout的比例布局(转载)
关于android LinearLayout的比例布局,主要有以下三个属性需要设置: 1,android:layout_width,android:layout_height,android:layo ...
- Mono for Android (3)-- AbsoluteLayout、FrameLayout、LinearLayout、RelativeLayout、TableLayout
AbsoluteLayout:允许开发人员将视图放在所定义的位置.该布局已经过时了,建议改用其他 FrameLayout:最简单的布局选项,其设计目的是在屏幕上显示单个对象.所有元素都固定在左上角.如 ...
随机推荐
- ASP.NET WebForm / MVC 源码分析
浏览器 Url:https//localhost:6565/Home/Index ,https//localhost:6565/WebForm1.aspx,请求服务器(构建请求报文,并且将请求报文发送 ...
- iOS开展-Xcode技巧总结(持续更新)
1. <LLDB调试命令初探> 2. <Xcode LLDB Debug教程> 3. <iOS开发准备篇-(5)Xcode调试技巧_1> 4. <iOS开发准 ...
- Git使用操作指南和GitHub
本文记录Git的使用操作,把散落的记忆整理到一起.并介绍GitHub的使用. 使用Git代表着一种思想和境地,和SVN相比,不是技术上的差异有多么大,而是代表融入了一种新的生态环境.一种开放开源的心态 ...
- 如何设置一个activity透明
1.在AndroidManifest.xml文件中设置: android:theme="@android:style/Theme.Translucent 此代码固定为全背景透明. 2.在Ac ...
- 生活中的大数据 hadoop
大数据和我有关吗?大数据就是大量的数据吗?只有互联网公司才有大数据吗?想盘活大数据必须买昂贵的软硬件吗?大数据怎么存储计算?大数据,这个时下最火热的互联网词语,你了解多少呢?
- 检验身份证的正确性(C语言版本)
/* check id_card * write by sndnvaps<sndnvaps@gmail.com> * ai -> a1 , a2, a3, a4, a5, a6... ...
- cocos2d之Box2D详细说明 鼠标联合实现
cocos2d之Box2D具体解释 鼠标关节实现 DionysosLai2014-5-7 我们常常要移动物理世界中的某个物体,例如说石头.木块等.假设我们直接改变这些物体的位置,让这些物体尾随我们手指 ...
- MVC 检测用户是否登录
当我们访问一个网站的需求检測用户是否已经登录(通过Session是否为null),我们知道在WebForm中能够定义一个BasePage类让他继承System.Web.UI.Page,重写它 ...
- Android Widget 小部件(一) 简单实现
在屏幕上加入Widget:或长按屏幕空白处,或找到WidgetPreview App选择. 原生系统4.0下面使用长按方式,4.0及以上 打开WIDGETS 创建Widget的一般步骤: 在menif ...
- Eclipse在Jar形成和应用程序包
最近的熟悉Java语言.在学习过程中Eclipse经常使用再熟悉它.本文简单说下Jar形成和应用程序包. Java在Jar相当于包C/C++该lib库,它是.class文件打包:经常使用Jar包有AP ...