zoukankan      html  css  js  c++  java
  • android support Percent支持库开发

    Android的布局支持百分比的设置进行开发,来学习如何去实现它,不过看起来会像网页的设置,比如宽度的设置属性是`layout_widthPercent`。在此之前,我们一般都会设置Linearlayout的weight权重来实现布局间的比例大小。

    Percent support Library提供了两个新的类:

    1.PercentRelativeLayout

    2.PercentFrameLayout

    创建新项目 

    创建一个新的项目来测试,修改`build.gradle`,需要引入以下库

    `applyplugin:'com.android.application'
    
    android {
    
    compileSdkVersion23
    
    buildToolsVersion"23.0.0"
    
    defaultConfig {
    
    applicationId"com.android.chaowen.percentdemo1"
    
    minSdkVersion7
    
    targetSdkVersion22
    
    versionCode1
    
    versionName"1.0"
    
    }
    
    buildTypes {
    
    release {
    
    minifyEnabledfalse
    
    proguardFilesgetDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
    
    }
    
    }
    
    }
    
    dependencies {
    
    compile fileTree(dir:'libs',include: ['*.jar'])
    
    compile'com.android.support:support-annotations:23.0.0'
    
    compile'com.android.support:appcompat-v7:23.0.0'
    
    compile'com.android.support:design:23.0.0'
    
    compile'com.android.support:percent:23.0.0'
    
    }
    

      创建布局

    xmlns:android="http://schemas.android.com/apk/res/android"
    
    xmlns:app="http://schemas.android.com/apk/res-auto"
    
    xmlns:tools="http://schemas.android.com/tools"
    
    android:layout_width="match_parent"
    
    android:layout_height="match_parent"
    
    tools:context=".MainActivity">
    
    android:id="@+id/first"
    
    android:background="@color/sa_green_dark"
    
    app:layout_heightPercent="50%"
    
    app:layout_marginLeftPercent="25%"
    
    app:layout_marginTopPercent="25%"
    
    app:layout_widthPercent="50%" />
    
    android:layout_width="0dp"
    
    android:layout_height="32dp"
    
    android:layout_alignLeft="@id/first"
    
    android:layout_alignStart="@id/first"
    
    android:layout_alignRight="@id/first"
    
    android:layout_alignEnd="@id/first"
    
    android:layout_below="@id/first"
    
    android:layout_marginTop="8dp"
    
    android:background="@color/light_grey" />

    比例大小是通过`heightPercent`和`widthPercent`属性来设置百分比大小值。完全属于`RelativeLayout`的扩展类,值得一提的是,

    不再需要设置`layout_width`和`layout_height`,注意了,这是新的库使用方法,因为这两个属性会被自动加入了。

    百度比也可以用于设置边距。唯一区别的只是采取了百分比值。

    最后一点需要注意,在第二个view,并没有直接设置比例的大小,但是它的位置是相对于第一个view.

  • 相关阅读:
    WinForm界面开发之布局控件"WeifenLuo.WinFormsUI.Docking"的使用
    分享几个.NET WinForm开源组件,纪念逐渐远去的WinForm。。。
    小议主子表INT自增主键插入记录的方法SQL server]教程
    微软工程师主讲的SqlServer2005视频教程
    11 个重要的数据库设计规则
    sql数据库设计学习---数据库设计规范化的五个要求
    YY淘宝商品数据库设计
    ASP.NET MVC的客户端验证:jQuery的验证
    ASP.NET MVC的客户端验证:jQuery验证在Model验证中的实现
    UNIX标准化及实现之POSIX标准可选头文件
  • 原文地址:https://www.cnblogs.com/andgoo/p/4781204.html
Copyright © 2011-2022 走看看