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

我们先来看看效果:

     

看一下布局:

PercentRelativeLayout

<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">

    <View

        android:id="@+id/top_left"

        android:layout_width="0dp"

        android:layout_height="0dp"

        android:layout_alignParentTop="true"

        android:background="#ff44aacc"

        app:layout_heightPercent="20%"

        app:layout_widthPercent="70%" />

    <View

        android:id="@+id/top_right"

        android:layout_width="0dp"

        android:layout_height="0dp"

        android:layout_alignParentTop="true"

        android:layout_toRightOf="@+id/top_left"

        android:background="#ffe40000"

        app:layout_heightPercent="20%"

        app:layout_widthPercent="30%" />

    <View

        android:id="@+id/bottom"

        android:layout_width="match_parent"

        android:layout_height="0dp"

        android:layout_below="@+id/top_left"

        android:background="#ff00ff22"

        app:layout_heightPercent="80%" />

</android.support.percent.PercentRelativeLayout>

PercentFrameLayout

<android.support.percent.PercentFrameLayout

    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">

        <!-- ... XML CODE -->

</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. 扩展 IHttpModule

    上篇提到请求进入到System.Web后,创建完HttpApplication对象后会执行一堆的管道事件,然后可以通过HttpModule来对其进行扩展,那么这篇文章就来介绍下如何定义我们自己的mod ...

  2. 递归删除N天前的文件夹及子文件夹下的特定文件

    @echo offrem 设置被删除文件夹路径set SrcDir=D:\tmp\test\rem 设置文件保存天数set Days=2rem /p指定搜索文件的路径 /s 在子目录中搜索 /m 指定 ...

  3. hdfs深入:06、hdfs的写入过程

    7.HDFS的文件写入过程 详细步骤解析: 1. client发起文件上传请求,通过RPC与NameNode建立通讯,NameNode检查目标文件是否已存在,父目录是否存在,返回是否可以上传: 2. ...

  4. S​Q​L​_​S​e​r​v​e​r​_​2​0​0​8​定​期​自​动​备​份​详​细​图​解

    S​Q​L​_​S​e​r​v​e​r​_​2​0​0​8​定​期​自​动​备​份​详​细​图​解 设置自动数据库的定期备份计划. http://wenku.baidu.com/link?url=Tu ...

  5. webpack4前端工程化教程(一)

    -本文作为webpack小白入门文章,会详细地介绍webpack的用途.具体的安装步骤.注意事项.一些基本的配置项,并且会以一个具体的项目实例来介绍如何使用webpack.另外,本文会简单地介绍一些最 ...

  6. 笔试算法题(35):最长递增子序列 & 判定一个字符串是否可由另一个字符串旋转得到

    出题:求数组中最长递增子序列的长度(递增子序列的元素可以不相连): 分析: 解法1:应用DP之前需要确定当前问题是否具有无后效性,也就是每个状态都是对之前状态的一个总结,之后的状态仅会受到前一个状态的 ...

  7. MYSQL每日一学 - 时间间隔表达式

    参考链接:https://dev.mysql.com/doc/refman/5.7/en/expressions.html Interval表达式(Temporal intervals)的使用 Int ...

  8. Kvm:启动报错:error: internal error: process exited while connecting to monitor: 2018-11-12T01:47:14.993371Z qemu-system-x86_64: cannot set up guest memory 'pc.ram': Cannot allocate memory

    今天有台kvm挂了,物理机启动时报错 很明显看报错显示内存不足,无法分配内存,查看物理机内存使用正常,.xml修改虚机内存后启动依然报错 报错: 这时候需要看一下主机确保可以分配多少内存 sysctl ...

  9. Python 3安装体验篇(win10)

    一.下载 1.打开官网https://www.python.org/downloads/windows/,点击Python 3版本链接 2.点击win10 64位安装链接,即可下载Python安装 二 ...

  10. PyQt5+requests实现车票查询工具

    PyQt5+requests实现一个车票查询工具,供大家参考,具体内容如下 结构图   效果图   思路 1.search(QPushButton)点击信号(clicked)连接到自定义的槽函数(ev ...