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. leetcode_Stone Game_dp_思维

    Alex和Lee玩游戏,共有偶数堆石头,石头总数为奇数,两人每次要么拿第一堆,要么拿最后一堆,两人以最优策略拿石堆(一次拿走完整的一堆),Alex先手,Alex赢返回True,否则返回False. 思 ...

  2. Fragment Transactions和Activity状态丢失

    本文由 伯乐在线 - 独孤昊天 翻译.未经许可,禁止转载!英文出处:androiddesignpatterns.欢迎加入翻译组. 下面的堆栈跟踪和异常代码,自从Honeycomb的初始发行版本就一直使 ...

  3. show()的方向

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  4. C++操作MYSQL遇到的一些问题

    首先 我使用的是 vcpkg<不知道的可以进行百度 可以剧透一下,这个对Visual Studio使用一些C++的轮子太方便了, 上面是我装的一些库<大大安利vcpkg 安装时一定要使用p ...

  5. HDU4415 Assassin’s Creed

    题目大意:有n个人,每个人有x,y两个值.x代表干掉他得到的分数,分数和不超过m;y代表干掉他后你能额外干掉多少个,且不计入总分. 求干掉人数最多为多少,以及最小的分. ~~~~~~~~~~~~~~~ ...

  6. solr-5.3.1配置(win7 x64)

    下载solr,下载地址http://www.eu.apache.org/dist/lucene/solr/5.3.1/solr-5.3.1.zip 解压到某个目录下,这里是解压到了d盘目录下,路径:D ...

  7. LINUX:Contos7.0 / 7.2 LAMP+R 下载安装Mysql篇

    文章来源:http://www.cnblogs.com/hello-tl/p/7569097.html 更新时间:2017-09-21 16:06 简介 LAMP+R指Linux+Apache+Mys ...

  8. table JS合并单元格

    function _w_table_rowspan(_w_table_id,_w_table_colnum){ _w_table_firsttd = ""; _w_table_cu ...

  9. 对Spring框架的理解(转)

    ①  spring框架是一个开源而轻量级的框架,是一个IOC和AOP容器 ② spring的核心就是控制反转(IOC)和面向切面编程(AOP) ③  控制反转(IOC):是面向对象编程中的一种设计原则 ...

  10. 【01】什么是AJAX

    什么是AJAX   AJAX(异步 JavaScript 和 XML)是 synchronous(英[ˈsɪŋkrənəs]) JavaScript and XML 的简称. AJAX不是一门新的编程 ...