Android 最终官方支持按百分比来设置控件的宽高了。

我们先来看看效果:

     

看一下布局:

PercentRelativeLayout

  1. <android.support.percent.PercentRelativeLayout
  2.  
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5. xmlns:app="http://schemas.android.com/apk/res-auto"
  6.  
  7. android:layout_width="match_parent"
  8.  
  9. android:layout_height="match_parent">
  10.  
  11. <View
  12.  
  13. android:id="@+id/top_left"
  14.  
  15. android:layout_width="0dp"
  16.  
  17. android:layout_height="0dp"
  18.  
  19. android:layout_alignParentTop="true"
  20.  
  21. android:background="#ff44aacc"
  22.  
  23. app:layout_heightPercent="20%"
  24.  
  25. app:layout_widthPercent="70%" />
  26.  
  27. <View
  28.  
  29. android:id="@+id/top_right"
  30.  
  31. android:layout_width="0dp"
  32.  
  33. android:layout_height="0dp"
  34.  
  35. android:layout_alignParentTop="true"
  36.  
  37. android:layout_toRightOf="@+id/top_left"
  38.  
  39. android:background="#ffe40000"
  40.  
  41. app:layout_heightPercent="20%"
  42.  
  43. app:layout_widthPercent="30%" />
  44.  
  45. <View
  46.  
  47. android:id="@+id/bottom"
  48.  
  49. android:layout_width="match_parent"
  50.  
  51. android:layout_height="0dp"
  52.  
  53. android:layout_below="@+id/top_left"
  54.  
  55. android:background="#ff00ff22"
  56.  
  57. app:layout_heightPercent="80%" />
  58.  
  59. </android.support.percent.PercentRelativeLayout>

PercentFrameLayout

  1. <android.support.percent.PercentFrameLayout
  2.  
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4.  
  5. xmlns:app="http://schemas.android.com/apk/res-auto"
  6.  
  7. android:layout_width="match_parent"
  8.  
  9. android:layout_height="match_parent">
  10.  
  11. <!-- ... XML CODE -->
  12.  
  13. </android.support.percent.PercentFrameLayout>

Stylable :

  • heightPercent
  • widthPercent
  • marginBottomPercent
  • marginEndPercent
  • marginLeftPercent
  • marginPercent
  • marginRightPercent
  • marginStartPercent
  • marginTopPercent

支持:

  • Android SDK v22
  • Android Build Tools v22.0.1
  • Android Percent Support Repository v22.2.0
  • Android Support v4 Repository v22.2.0
according to the the manifest minsdk is v7 (android 2.1)

android PercentRelativeLayout 支持百分比来设置控件的宽高的更多相关文章

  1. Android 终于官方支持按百分比来设置控件的宽高了

    dependencies { compile 'com.android.support:percent:22.2.0' } 支持布局 PercentRelativeLayout <android ...

  2. Android在onCreate中获取控件的宽高

    在某些需求下,我们需要在onCreate的时候就获取到控件的宽高,但是如果直接用view.getWidth()或view.getHeight()会得到0.这是因为在onCreate执行的时候,控件还没 ...

  3. activity 中获取控件的宽高

    1.第一种方式: TextView textview3 = findViewById(R.id.textview3); textView3.post(new Runnable() { @Overrid ...

  4. Android初级教程_获取Android控件的宽和高

    转载:http://blog.csdn.net/johnny901114/article/details/7839512 我们都知道在onCreate()里面获取控件的高度是0,这是为什么呢?我们来看 ...

  5. 我的Android进阶之旅------>如何获取Android控件的宽和高

    本文转载于:http://blog.csdn.net/johnny901114/article/details/7839512 我们都知道在onCreate()里面获取控件的高度是0,这是为什么呢?我 ...

  6. 【转】获取Android控件的宽和高

    我们都知道在onCreate()里面获取控件的高度是0,这是为什么呢?我们来看一下示例: 首先我们自己写一个控件,这个控件非常简单: public class MyImageView extends ...

  7. android 设置控件的颜色,字体

    1.用代码设置控件的颜色:    int b =  getResources().getColor(R.drawable.blue);//得到配置文件里的颜色    mButton.setTextCo ...

  8. android屏幕适配的全攻略3-动态获取手机屏幕宽高及动态设置控件宽高

    1.获取手机屏幕宽高: DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetr ...

  9. Android线程中设置控件

    在Android中经常出现多线程中设置控件的值报错的情况,今天教大家封装一个简单的类避免这样的问题,同样也调用实现也非常的方便. 自定义类: /** * Created by wade on 2016 ...

随机推荐

  1. CAD交互绘制带颜色宽度的直线(com接口)

    用户可以在控件视区任意位置绘制直线. 主要用到函数说明: _DMxDrawX::DrawLine 绘制一个直线.详细说明如下: 参数 说明 DOUBLE dX1 直线的开始点x坐标 DOUBLE dY ...

  2. Vue之x-template(2)

    将html结构写在一对script标签中,设置type=“x-template” <!DOCTYPE html> <html> <head lang="en&q ...

  3. Python 迭代器-生成器-面向过程编程

    上节课复习:1. 函数的递归调用 在调用一个函数的过程中又直接或者间接地调用了函数本身称之为函数的递归 函数的递归调用有两个明确的阶段: 1. 回溯 一层一层地调用本身 注意: 1.每一次调用问题的规 ...

  4. 基于Vue的简单日历组件

    日历组件 由于移动端项目中需要用到日历组件,网上找了下,没看到几个合适的,就尝试着自己写一个.然后发现也不是很复杂,目前只做了最基本的功能,大家也可以拿去做做二次开发. 如何写一个日历组件 基础效果如 ...

  5. PHP 反射API

    出处:http://blog.csdn.net/hguisu/article/details/7357421 PHP5添加了一项新的功能:Reflection.这个功能使得phper可以reverse ...

  6. DAG模型(矩形嵌套)

    推荐在线例题:http://acm.nyist.net/JudgeOnline/problem.php?pid=16 题摘: 矩形嵌套 时间限制:3000 ms  |  内存限制:65535 KB 难 ...

  7. 2017 GDCPC 省赛总结

    第一年参加省赛,也是我接触acm半年多的第一个正式省级赛事,这半年来我为acm付出的可能很多,但经历过这次省赛后,给我唯一的感觉就是,还不够多. 直接分析题目吧,开始拿到试题后我读的是A题,然后我的队 ...

  8. matplotlib多种绘图方式

    目录 散点图 条形图 直方图 总结 散点图 假设通过爬虫你获取到了北京2016年3,10月份每天白天的最高气温(分别位于列表a,b),那么此时如何寻找出气温和随时间(天)变化的某种规律? a = [1 ...

  9. nyoj 2 括号配对问题(stack)

    括号配对问题 时间限制:3000 ms  |            内存限制:65535 KB 难度:3   描述 现在,有一行括号序列,请你检查这行括号是否配对.   输入 第一行输入一个数N(0& ...

  10. CentOS虚拟机与本机同步时间

    接着之前的任务,还是为了在VMWare上搭建分布式hadoop集群.搭着搭着注意到虚拟机上的时间和本机是不同步的,而且可以说是乱七八糟,3台虚拟机时间都与本机差了8个小时以上.首先确认不是时区的问题, ...