与《第一行代码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 代码设置来电铃声
  2. Android自定义Dialog(自定义主题、自定义布局)
  3. Android 的整体布局
  4. android 执行shell命令代码
  5. android 开发中常用颜色,以及一些颜色的代码
  6. Android Camera子系统之源代码View
  7. android 五种 布局文件
  8. Android开发之常用代码片段

随机推荐

  1. 解决Warning:android-apt plugin is inco
  2. Android全屏时软键盘遮住输入框修改布局
  3. Android Studio(二):快捷键设置、插件安装
  4. Android(安卓)基于Bmob云的商品查询显示
  5. Android setBackground的一个小问题
  6. Android(安卓)实现阅读pdf格式的文件和an
  7. Android中BroadCastReceiver使用(整理)
  8. Android利用wireshark抓取网络数据包
  9. Android中设置中文粗体的方法
  10. 友盟推送android 8.0系统不显示推送消息