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. E. Wrong Answer

    E. Wrong Answer time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  2. 多线程下单例模式的实现_ThreadLocal_ReentrantLock

    package threadStudy; public class MultiThreadSingleInstance { // volatile 防止指令重排 private static vola ...

  3. Perl字符集就是方括号(或称中括号)里一连串可能的字符,只匹配单一字符,该单一字符可以是字符集里的任何一个,“-”在字符集里有特殊含义:表示某个范围的字符。而字符集意外的连字符不具有特殊意义。

    Perl字符集就是方括号(或称中括号)里一连串可能的字符,只匹配单一字符,该单一字符可以是字符集里的任何一个,“-”在字符集里有特殊含义:表示某个范围的字符.而字符集意外的连字符不具有特殊意义.

  4. iOS视频通话方案

    现在iPhone4平台上实时音视频对话已取得初步成果.其间查阅了很多资料,感谢这些信息的提供者.继往开来,我写下此文.我只列出要点,具体编码以及平台移植各位自己去努力吧.照着下面的步骤,您一定能做出来 ...

  5. 洛谷——P4053 [JSOI2007]建筑抢修

    P4053 [JSOI2007]建筑抢修 小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落消灭了所有z部落的入侵者.但是T部落的基地里已经有N个建筑设施受到了严重的 ...

  6. 样例GeoQuiz应用开发 第2章

    先介绍一下MVC,Model View Controller,是软件架构中最常见的一种框架. 简单来说就是通过 controller 的控制去操作 model 层的数据,并且返回给 view 层展示, ...

  7. python3.x Day4 模块!!

    json and pickle模块 用途是为了持久化信息,这种持久化方式可以和其他程序语言兼容,一般都支持json,json只能持久化数据,pickle是python特有的方式,可以持久化所有信息和数 ...

  8. 4.model 字段

    一.字段名 字段名 类型 参数 AutoField(Field) - int自增列, 必须填入参数 primary_key=True BigAutoField(AutoField) - bigint自 ...

  9. 简单的python代码实现语音朗读

    昨天女友生日,因为她一直对生日无感,所以我也就没有准备什么礼物.想起元旦前写的自动测试的脚本,添加了语音来提示测试和报告错误.灵机一动,为什么不用这个语音来庆祝她生日快乐呢?身为设计公司市场经理的她对 ...

  10. 创建Javaweb项目及MyEclipse视图的配置

    在myEclipse里--右键new--Web Project 视图的配置--Window--Show View-Other在里面输入要找的视图例如(servers)或者直接 Window--rese ...