Android开发--布局
一:LinearLayout
1、线性布局,这个东西,从外框上可以理解为一个div,他首先是一个一个从上往下罗列在屏幕上。每一个LinearLayout里面又可分为垂直布局(android:orientation="vertical")和水平布局(android:orientation="horizontal" )。当垂直布局时,每一行就只有一个元素,多个元素依次垂直往下;水平布局时,只有一行,每一个元素依次向右排列。
linearLayout中有一个重要的属性 android:layout_weight="1",这个weight在垂直布局时,代表行距;水平的时候代表列宽;weight值越大就越大。
2、TextView占一定的空间,没有赋值也有一定的宽高,要特别注意。
第一个实例
效果图:
代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="right"
>
<!-- android:gravity="right"表示Button组件向右对齐 -->
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="确定"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="取消"
/>
</LinearLayout>
</LinearLayout>
第二个实例:
效果图:
代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
> <TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:background="#3C3C3C" /> <TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FFEFD5"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:background="#66CDAA"
android:orientation="horizontal"
> <TextView
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#FFF663"
android:layout_weight="1"
/>
<TextView
android:id="@+id/txt2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#E82917"
android:layout_weight="4" />
<TextView
android:id="@+id/txt3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#FFF663"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
我们要做的就是多多实践,多看下关于软件的布局。软件上的布局和真机上的布局有差异,我们尽可能的拿真机去测验,并且在不同的机型上去测验。
Android开发--布局的更多相关文章
- Android开发——布局性能优化的一些技巧(一)
0. 前言 上一篇我们分析了为什么LinearLayout会比RelativeLayout性能更高,意义在于分析了这两种布局的实现源码,算是对一个小结论的证明过程,但是对布局性能的优化效果,对这两种布 ...
- android开发--布局三(微信布局)
微信主界面 我们布局应该从局来看,如上图,我们可以分为三个大的LinearLayout,再从LinearLayout嵌套其它布局,从而做出界面 文件 主界面代码: <LinearLayout x ...
- Android开发--布局二
1.Andrid:控件布局(表格布局)TableLayout 有多少个TableRow对象就有多少行, 列数等于最多子控件的TableRow的列数 直接在TableLayout加控件,控件会占据一行 ...
- 从零开始学android开发-布局中 layout_gravity、gravity、orientation、layout_weight
线性布局中,有 4 个及其重要的参数,直接决定元素的布局和位置,这四个参数是 android:layout_gravity ( 是本元素相对于父元素的重力方向 ) android:gravity (是 ...
- android开发布局优化之ViewStub
使用ViewStub可以延迟加载一个布局文件,提高显示速率.刚开始接触到,记录下来. 关于viewstub的使用,我们可以在不同的布局中使用,比如可以根据设备的大小动态决定显示哪个界面. viewst ...
- Android开发布局 案例一
权重:就是在布局界面中所占的比例 实践案例: <?xml version="1.0" encoding="utf-8"?> <LinearLa ...
- android开发布局文件imageview 图片等比例缩放:
ImageView的属性scaleType,如果等比缩放的话,就使用CenterInside,如果想固定大小的话,就CenterCrop <?xml version="1.0" ...
- Android开发——布局性能优化的一些技巧(二)
, 0, drawable.getMinimumWidth(),dra.getMinimumHeight()); tv.setCompoundDrawables(null, null, drawabl ...
- Android开发布局 案例二
实践案例: XML <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...
随机推荐
- 在文章没有缩略图的时候,如何去掉织梦官方的 DEDECMS无缩略图 图片
1.打开 list_article.htm.2.替换代码 将 [field:array runphp='yes']@me = (empty(@me['litpic']) ? “<a href=’ ...
- (转)android平台phonegap框架实现原理
(原文)http://blog.csdn.net/wuruixn/article/details/7405175 android平台phonegap框架实现原理 分类: Android2012-03- ...
- 如何解决requireJs的模块加载超时
requireJs的加载是一种异步机制,它加载js的时候有个默认的超时机制,当加载一个js超过一定时间的时候,它就会在浏览器中抛出模块加载超时错误,接下来,就不会加载这个模块. 这个机制其实是起到了节 ...
- UVALive 7302 (最短路)
Probelm Terrorists 题目大意 给一张n个点,m条边的无向图.共有q个询问,每次询问u到v的最短路. n <= 100000 , n-1 <= m <= n + 5 ...
- 一些sql语句的常用总结(重要)
select primary_flag from tc_contact where primary_flag !=0 select dept_id,dept_name,tree_level,tree_ ...
- [转]设置Android手机以使用ARM Streamline进行性能分析(一)
本博客第一次转载的文章,原文访问不到了,这篇是从google cache里挖出来的,为有需要的同学准备.原文地址 Posted by Fang Bao,(鲍方) 4 Comments 11 J ...
- squid ACL 大全
Access Controls in Squid Contents Access Controls in Squid The Basics: How the parts fit together AC ...
- [BZOJ 3530][Sdoi 2014]数数
阿拉~好像最近总是做到 AC 自动机的题目呢喵~ 题目的算法似乎马上就能猜到的样子…… AC 自动机 + 数位 dp 先暴力转移出 f[i][j] :表示从 AC 自动机上第 j 号节点走 i 步且不 ...
- BizTalk 中使用 WCF-OracleDB adapter
在使用BizTalk WCF-OracleDB adapter操作Oracle数据库时,遇到了一些问题,记录如下. 按照BizTalk的文档,目前BizTalk 2010支持的Oracle数据库版本如 ...
- ruby中http请求方法整理
#POST请求 请求包是json包 返回body并转换成json对象def post_json *args uri = URI.parse args[0] req = Net::HTTP::Post. ...