可能会遇到的问题:

1.由于使用的android studio版本比书上的高,需要另外添加依赖

在build.gradle中添加依赖

implementation 'androidx.percentlayout:percentlayout:1.0.0'

2.修改布局时,不仅需要修改button设置,还需要设置头tag

代码如下

<androidx.percentlayout.widget.PercentFrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"

本节源码

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<!--<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"-->
<!--<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"-->
<!--<PercentLayout xmlns:android="http://schemas.android.com/apk/res/android"-->
<androidx.percentlayout.widget.PercentFrameLayout xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"xmlns:tools="http://schemas.android.com/tools"tools:context=".MainActivity"><Buttonandroid:id="@+id/button1"android:text="Button 1"android:layout_gravity="left|top"app:layout_widthPercent="50%"app:layout_heightPercent="50%"tools:ignore="RtlHardcoded"android:layout_height="wrap_content"android:layout_width="wrap_content"/><Buttonandroid:id="@+id/button2"android:text="Button 2"android:layout_gravity="right|top"app:layout_widthPercent="50%"app:layout_heightPercent="50%"tools:ignore="RtlHardcoded"android:layout_height="wrap_content"android:layout_width="wrap_content"/><Buttonandroid:id="@+id/button3"android:text="Button 3"android:layout_gravity="left|bottom"app:layout_widthPercent="50%"app:layout_heightPercent="50%"tools:ignore="RtlHardcoded"android:layout_height="wrap_content"android:layout_width="wrap_content"/><Buttonandroid:id="@+id/button4"android:text="Button 4"android:layout_gravity="right|bottom"app:layout_widthPercent="50%"app:layout_heightPercent="50%"tools:ignore="RtlHardcoded"android:layout_height="wrap_content"android:layout_width="wrap_content"/></androidx.percentlayout.widget.PercentFrameLayout>
<!--</androidx.appcompat.widget.LinearLayoutCompat>-->

build.gradle

plugins {id 'com.android.application'
}android {compileSdk 32defaultConfig {applicationId "com.example.activitylifecycletest"minSdk 21targetSdk 32versionCode 1versionName "1.0"testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"}buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'}}compileOptions {sourceCompatibility JavaVersion.VERSION_1_8targetCompatibility JavaVersion.VERSION_1_8}
}dependencies {implementation 'androidx.appcompat:appcompat:1.3.0'implementation 'com.google.android.material:material:1.4.0'implementation 'androidx.constraintlayout:constraintlayout:2.0.4'implementation 'androidx.percentlayout:percentlayout:1.0.0'testImplementation 'junit:junit:4.13.2'androidTestImplementation 'androidx.test.ext:junit:1.1.3'androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'}

Android Studio《一行代码》3.3.4 百分比布局相关推荐

  1. 在Android Studio编写代码时,使用MaterialCardView的项目无法正常运行怎么办?简简单单搞定它_莫韵乐与bug的奇妙冒险

    在Android Studio编写代码时,使用MaterialCardView布局的项目闪退怎么办?简简单单搞定它 当我想用MaterialCardView去做一个好看的界面的时候,应用居然闪退了 经 ...

  2. android studio倒计时代码,AndroidStudio项目制作倒计时模块

    前言 大家好,给大家带来AndroidStudio项目制作倒计时模块的概述,希望你们喜欢 项目难度 AndroidStudio项目制作倒计时模块的难度,不是很大,就是主要用了Timer和TimerTa ...

  3. android studio同步代码块,Android Studio快捷键大全

    Ctrl+P 提示有效说明参数 Ait + Enter 提示 Ctrl+Ait+L 格式化 Ctrl+Y 删除本行 Alt + Shift + Up/Down 上下移动本行代码 Alt + Ctrl ...

  4. Android Studio的代码笔记--基本使用、新建一个项目、修改快捷键、常用控件的使用等

    基本使用 创建一个新项目 新建一个activity 修改主界面 新建一个布局并引用 app模块下的文件目录结构 res 下的常用资源目录 AndroidManifest.xml文件代码解释 Activ ...

  5. (转载)使用Android Studio对代码进行重构

    (转载)https://blog.csdn.net/guijiaoba/article/details/50608606 简介 2013年Google I/O大会上,谷歌推出新的Android开发环境 ...

  6. Android Studio查看代码行数和删除注释空行等

    在Android Studio中: 一.删除行注释 1.ctrl+r,打开替换功能.出现下图: 2.操作如图: 3.单击上图中的第4步替换之后,我示例程序中的那个黄色注释就没了,如果想要把所有行注释都 ...

  7. 给Android Studio设置代码字体大小与界面字体样式

    前言 使用android studio第一步肯定就是设置字体大小了,废话不多说,直接上教程: 初始界面: 更改后界面: 目录 更改代码字体大小 更改界面字体大小及样式 一.更改代码字体大小​ File ...

  8. Android Studio NDK 代码 Source Insight调试 (NDK 目前开发方案 | NDK 编译 | 导入 so 库 | 项目编码转换)

    作者 : 韩曙亮 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/52088039 最近在移植一个 JNI 项目, 比较纠结, A ...

  9. android studio开源代码,Android Studio Set of source 代码源集

    一.源集 1.定义:Android Studio 按逻辑关系将每个模块的源代码和资源进行分组,这个分组叫做源集. 2.main Module 源集包括其所有构建变体共用的代码和资源.这句话很关键,意思 ...

  10. android studio证件照代码,Android 修图(换证件照背景,污点修复)

    背景 前段时间的一个周末,一个女生让我帮她换一下他的证件照背景,我又没带电脑.我又不好意思拒接,怎么办呢?应用商店下载一个证件照换背景的APP,瞬间换完,我正准备保存时,跳出来一个支付框,如果你要保存 ...

最新文章

  1. Color Blended Layers
  2. 大推荐——家庭书架·成功读库系列
  3. 机器学习:梯度下降法,几种实现策略
  4. MATLAB设置x为0到10所有数,MATLAB教学_10数值微积分
  5. Java使用自定义包
  6. python rpy2后封装_转换rpy2的python对象
  7. 拿来就能用!去哪儿网消息中间件 QMQ 详解 | 技术头条
  8. vue-cli webpack配置注释
  9. 串口485接法图_RS232转换为RS485的接线方法最好有图
  10. c#绝对值函数图像_取绝对值(C#、C++、js)
  11. Android - Android Studio 加速Gradle Bulid 速度
  12. Java笔记——Java多线程~
  13. 借华为鸿蒙系统发布,谈谈操作系统的爱恨情仇发展史
  14. 一文看懂计算机视觉!7个专业术语别说你不知道!
  15. 使用有道词典API做一个简单的翻译页面 HTML+JS+有道词典API(代码可直接运行)
  16. 搜索引擎选型调研文档
  17. 工业相机的靶面尺寸怎么算
  18. PTA——7-4 有课几何
  19. libra测试环境搭建
  20. 揭秘——STL空间配置器

热门文章

  1. mysql 花生壳 2003_基于HTTP协议实现的小型web服务器的方法
  2. 【python】The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all
  3. 关于级联选择器Cascader数据太多会改变列表大小的问题
  4. redis.conf详解之replica-read-only
  5. 和李笑来学python——《自学是门手艺》
  6. 计算机网络学习07(DNS域名系统详解)
  7. cdma2000解析_CDMA2000 1x EV-DO技术解析
  8. AP侧,BP侧如何理解?
  9. Unity设计模式——享元模式(附代码)
  10. 【微信小程序】图片违法违规内容鉴别