android 百分比布局(percentLayout),妈妈再也不用担心适配问题了
2015-09-21 16:04
861 查看
今天事情比较少,没事做就瞎看看,尽然发现android尽然能够像web一样支持百分比布局了,实在是激动人心(以后面试谁再问我适配的问题,我他妈一定要打死他),下面看看如何实现一个百分比布局的页面。
首先添加支持:Project Structure 面板添加:com.android.support:percent:22.2.0
![](http://img.blog.csdn.net/20150921155553874?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
依赖添加好之后可以在build.grade中看见:
到这里已经就可以了,是不是超级简单。
下面看下代码:
看下效果:
![](http://img.blog.csdn.net/20150921160145804?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
非常简单,但是也很实用。
目前好像只有relativelayout 和framelayout 支持百分比,linearlayout暂时还没有,不过linearlayout有weight属性,不怕!
首先添加支持:Project Structure 面板添加:com.android.support:percent:22.2.0
依赖添加好之后可以在build.grade中看见:
compile 'com.android.support:percent:22.2.0'
到这里已经就可以了,是不是超级简单。
下面看下代码:
<?xml version="1.0" encoding="utf-8"?> <android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:gravity="center" android:text="80%" android:background="@android:color/holo_green_dark" app:layout_widthPercent="80%" android:layout_height="0dp" android:layout_width="0dp" app:layout_heightPercent="30%" /> </android.support.percent.PercentRelativeLayout>
看下效果:
非常简单,但是也很实用。
目前好像只有relativelayout 和framelayout 支持百分比,linearlayout暂时还没有,不过linearlayout有weight属性,不怕!
相关文章推荐
- android 事件总线 -- Otto(一)
- android开发步步为营之77:android数据库ORM之greenDAO
- Android-在线查看源码
- Android开源组件SlidingMenu的基本使用方法和SlidingMenuDemo
- Android中常见的像素单位
- android获取系统wifi状态等
- Android Studio快捷键设置
- 【android】通过leakCanary找出程序内存泄露点
- Android布局优化之<merge>与<ViewStub>标签使用
- Android自定义View示例(一)—带有删除按钮的EditText
- Android快速开发工具GsonFormat使用教程
- android弹出下拉选择菜单,单选,多选【运行截图——图】
- android Bitmap getByteCount和getRowBytes
- android studio集成svn
- 解决android代码中重复写findViewByid()
- android客户端性能测试 (一)
- Android 性能测试
- Android 官方推荐 : DialogFragment 创建对话框
- android布局相关
- android studio ndk