与《第一行代码Android》中作者所述内容不同,AS 3.5.1的build.gradle内部是这样的

dependencies {    implementation fileTree(dir: 'libs', include: ['*.jar'])    implementation 'androidx.appcompat:appcompat:1.1.0'    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'    testImplementation 'junit:junit:4.12'    androidTestImplementation 'androidx.test.ext:junit:1.1.1'    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'}

可以看到和书上的内容不同,通过查阅android developers,得知在java上的percent类已经被弃用了,官方给出了另一种做法,先贴代码

<androidx.constraintlayout.widget.ConstraintLayout         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">     <androidx.constraintlayout.widget.Guideline         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/left_guideline"         app:layout_constraintGuide_percent=".15"         android:orientation="vertical"/>     <androidx.constraintlayout.widget.Guideline         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/right_guideline"         app:layout_constraintGuide_percent=".85"         android:orientation="vertical"/>     <androidx.constraintlayout.widget.Guideline         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/top_guideline"         app:layout_constraintGuide_percent=".15"         android:orientation="horizontal"/>     <androidx.constraintlayout.widget.Guideline         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/bottom_guideline"         app:layout_constraintGuide_percent=".85"         android:orientation="horizontal"/>     <Button         android:text="Button"         android:layout_width="0dp"         android:layout_height="0dp"         android:id="@+id/button"         app:layout_constraintLeft_toLeftOf="@+id/left_guideline"         app:layout_constraintRight_toRightOf="@+id/right_guideline"         app:layout_constraintTop_toTopOf="@+id/top_guideline"         app:layout_constraintBottom_toBottomOf="@+id/bottom_guideline" /> </androidx.constraintlayout.widget.ConstraintLayout>

本人作为初学者已经懵逼了,对于上述代码官方给出的说法是:

consider using ConstraintLayout and associated layouts instead
考虑改用ConstraintLayout和关联的布局。

所以有能力的可以考虑上述做法用java实现百分比布局
Android Developers网站:https://developer.android.google.cn/?hl=en

更多相关文章

  1. android Java代码的启动
  2. Android(安卓)代码设置来电铃声
  3. Android(安卓)Timer的用法示例
  4. android 执行shell命令代码
  5. android 开发中常用颜色,以及一些颜色的代码
  6. Android很有用的代码片段
  7. android 插件化 与一个轻量级框架
  8. android 开发中常用颜色,以及一些颜色的代码
  9. android监控来电显示

随机推荐

  1. android ViewPager学习笔记1
  2. android添加监听器
  3. Android(安卓)混淆打包
  4. Android WIFI,蓝牙,电池,背光,SD卡,摄像头,按键
  5. Android adb.exe程序启动不起来
  6. android Activity间List传值
  7. Android 消息通知栏Notification使用和权
  8. Android Property实现介绍
  9. 如何获得Android的System Bar’s Height
  10. Could not find gradle wrapper within A