博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android UI-Layout界面布局
阅读量:4292 次
发布时间:2019-05-27

本文共 3000 字,大约阅读时间需要 10 分钟。

Android对用五大布局对象,它们分别是FrameLayout(框架布局),LinearLayout (线性布局),AbsoluteLayout(绝对布局),RelativeLayout(相对布局),TableLayout(表格布局). 

FrameLayout: 叠加对象/帧布局(组界面布局)

将所有的子元素放在整个界面的左上角,后面的子元素直接覆盖前面的子元素,所以用的比较少。

LinearLayout: 线性布局

 线性布局是按照水平或垂直的顺序将子元素(可以是控件或布局)依次按照顺序排列,每一个元素都位于前面一个元素之后。线性布局分为两种:水平方向和垂直方向的布局。

RelativeLayout:相对于ID 布局对象

 RelativeLayout继承于android.widget.ViewGroup,其按照子元素之间的位置关系完成布局的,作为Android系统五大布局中最灵活也是最常用的一种布局方式,非常适合于一些比较复杂的界面设计。

TableLayout: 表格布局对象
<TableRow></TableRow>

每个TableLayout是由多个TableRow组成,一个TableRow就表示TableLayout中的每一行,这一行可以由多个子元素组成。实际上TableLayout和TableRow都是LineLayout线性布局的子类。

AbsoluteLayout: 绝对元素定位对象

   绝对布局中将所有的子元素通过设置android:layout_x 和 android:layout_y属性,将子元素的坐标位置固定下来,即坐标(android:layout_x, android:layout_y) ,layout_x用来表示横坐标,layout_y用来表示纵坐标。 屏幕左上角为坐标(0,0),横向往右为正方,纵向往下为正方。

其他布局:

GridLayout:

在最新的Android 4.0 SDK中,新引入了GridLayout的布局样式,这个布局样式看上去可能有点象之前的TableLayout,但实际上还是有所不同的。GridLayout可以用来做一个象TableLayout这样的布局样式,但其性能及功能都要比tablelayout要好,比如GridLayout的布局中的单元格可以跨越多行,而tablelayout则不行,此外,其渲染速度也比tablelayout要快。

DrawerLayout:抽屉布局

抽屉导航 

没有android官方控件时,很多时候都是使用开源的SlidingMenu,一直没机会分析侧拉菜单的实现机理,本文将分析android.support.v4.widget.DrawerLayout的使用及实现。

DrawerLayout acts as a top-level container for window content that allows for interactive "drawer" views to be pulled out from the edge of the window.
Drawer positioning and layout is controlled using the android:layout_gravity attribute on child views corresponding to which side of the view you want the drawer to emerge from: left or right. (Or start/end on platform versions that support layout direction.)
To use a DrawerLayout, position your primary content view as the first child with a width and height of match_parent. Add drawers as child views after the main content view and set the layout_gravity appropriately. Drawers commonly use match_parent for height with a fixed width.
DrawerLayout.DrawerListener can be used to monitor the state and motion of drawer views. Avoid performing expensive operations such as layout during animation as it can cause stuttering; try to perform expensive operations during the STATE_IDLE state. DrawerLayout.SimpleDrawerListener offers default/no-op implementations of each callback method.
As per the Android Design guide, any drawers positioned to the left/start should always contain content for navigating around the application, whereas any drawers positioned to the right/end should always contain actions to take on the current content. This preserves the same navigation left, actions right structure present in the Action Bar and elsewhere

NavigationDrawerFragment.NavigationDrawerCallbacks

onNavigationDrawerItemSelected(int){}
isDrawerOpen()

NavigationDrawerFragment:(NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer)

setUp()

FragmentManager: getFragmentManager()

beginTransaction()

ActionBar:getActionBar()

setNavigationMode()
setDisplayShowTitleEnabled()
setTitle()

Fragment

setArguments(Bundle)
onCreateView(LayoutInflater,ViewGroup,Bundle)
onAttach(Activity)

转载地址:http://okegi.baihongyu.com/

你可能感兴趣的文章
count(*),count(1)和count(字段)的区别
查看>>
面试大杀器:为什么一定要用MQ中间件?
查看>>
漫谈 MySQL 的锁机制
查看>>
Java 中 long 和 double 的原子性?
查看>>
Nginx和Apache的对比
查看>>
一文带你看懂Spring事务!
查看>>
Spring Boot实战:拦截器与过滤器
查看>>
夯实基础:关于线程的Callable和Future两个类解析
查看>>
常用的设计模式汇总,超详细!
查看>>
一篇文章了解RPC框架原理
查看>>
技术进阶:ThreadPoolExecutor源码解析之机制原理篇
查看>>
nginx搭建简易负载均衡服务
查看>>
SpringCloud之Feign(Finchley版)
查看>>
应用框架:Spring IOC基于注解启动的分析
查看>>
基于注解@Aspect的AOP实现
查看>>
Redis 高可用集群
查看>>
Redis 布隆过滤器实战「缓存击穿、雪崩效应」
查看>>
Redis持久化存储详解(一)
查看>>
Spring Boot 面试,一个问题就干趴下了!
查看>>
深度解析SpringCloud之服务注册与发现机制(万字深度好文)
查看>>