網站首頁 編程語言 正文
《第一行代碼》版本2,那個百分比布局已經被棄用了,令人頭大。
解決方法,在build.gradle下面添加一句androidx.percent…,看下面,然后sync一下:
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.percentlayout:percentlayout:1.0.0'
...
}
然后xml中的開頭布局也改一下,但其實還是可以看出來它被劃線了:
<?xml version="1.0" encoding="utf-8"?>
<androidx.percentlayout.widget.PercentFrameLayout 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=".FourthActivity">
<Button
android:id="@+id/button_1"
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
android:layout_gravity="left|top"
android:text="button1"
android:textAllCaps="false"/>
<Button
android:id="@+id/button_2"
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
android:layout_gravity="right|top"
android:text="button2"
android:textAllCaps="false"/>
<Button
android:id="@+id/button_3"
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
android:layout_gravity="left|bottom"
android:text="button3"
android:textAllCaps="false"/>
<Button
android:id="@+id/button_4"
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
android:layout_gravity="right|bottom"
android:text="button4"
android:textAllCaps="false"/>
</androidx.percentlayout.widget.PercentFrameLayout>
然后可以運行了,效果如下:
原文鏈接:https://blog.csdn.net/qq_43738932/article/details/126040023
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-06-24 python函數常見關鍵字分享_python
- 2022-05-20 python使用數字與字符串方法技巧_python
- 2022-03-19 Android使用DocumentFile讀寫外置存儲的問題_Android
- 2022-03-19 centos7修改網卡后無法上網問題解決過程_Linux
- 2022-03-30 ASP.NET?Core使用JWT自定義角色并實現策略授權需要的接口_實用技巧
- 2022-08-22 C++貪心算法處理多機調度問題詳解_C 語言
- 2022-12-26 python?時間處理之月份加減問題_python
- 2022-11-17 Go語言學習教程之指針的示例詳解_Golang
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支