[Android新手学习笔记21]-百分比布局

使用前需要在app/build.gradle文件中添加如下内容:

compile 'com.android.support:percent:25.1.1'

注意25.1.1为版本,有要求,和上面版本填一样。

  
  
  1. dependencies {
  2.    compile fileTree(dir: 'libs', include: ['*.jar'])
  3.    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
  4.        exclude group: 'com.android.support', module: 'support-annotations'
  5.    })
  6.    compile 'com.android.support:appcompat-v7:25.1.1'
  7.    compile 'com.android.support:percent:25.1.1'
  8.    testCompile 'junit:junit:4.12'
  9. }

修改app/build.gradle文件时,会提示:

Gradle files have changed since last project sync. A project sync may be necessary for the IDE to work properly. Sync Now

点击Sync Now即可。

基本配置如下:

  
  
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <android.support.percent.PercentFrameLayout
  3.    xmlns:android="http://schemas.android.com/apk/res/android"
  4.    xmlns:app="http://schemas.android.com/apk/res-auto"
  5.    android:layout_width="match_parent"
  6.    android:layout_height="match_parent">
  7.    <Button
  8.        android:id="@+id/button1"
  9.        android:text="Button"
  10.        android:layout_gravity="left|top"
  11.        app:layout_widthPercent="50%"
  12.        app:layout_heightPercent="50%" />
  13.    <Button
  14.        android:id="@+id/button2"
  15.        android:text="Button"
  16.        android:layout_gravity="right|top"
  17.        app:layout_widthPercent="50%"
  18.        app:layout_heightPercent="50%" />
  19.    <Button
  20.        android:id="@+id/button3"
  21.        android:text="Button"
  22.        android:layout_gravity="left|bottom"
  23.        app:layout_widthPercent="50%"
  24.        app:layout_heightPercent="50%" />
  25.    <Button
  26.        android:id="@+id/button4"
  27.        android:text="Button"
  28.        android:layout_gravity="right|bottom"
  29.        app:layout_widthPercent="50%"
  30.        app:layout_heightPercent="50%" />
  31. </android.support.percent.PercentFrameLayout>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值