網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
《第一行代碼》版本2,那個(gè)百分比布局已經(jīng)被棄用了,令人頭大。
解決方法,在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中的開頭布局也改一下,但其實(shí)還是可以看出來(lái)它被劃線了:
<?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>
然后可以運(yùn)行了,效果如下:
原文鏈接:https://blog.csdn.net/qq_43738932/article/details/126040023
- 上一篇:沒(méi)有了
- 下一篇:沒(méi)有了
相關(guān)推薦
- 2022-07-13 SpringBoot中的SmartInitializingSingleton接口的使用
- 2024-03-07 基于配置類方式管理Bean
- 2022-05-19 python?字符串常用方法超詳細(xì)梳理總結(jié)_python
- 2022-08-07 Go?Grpc?Gateway兼容HTTP協(xié)議文檔自動(dòng)生成網(wǎng)關(guān)_Golang
- 2022-04-20 Python設(shè)計(jì)模式結(jié)構(gòu)型享元模式_python
- 2022-09-20 C#單線程和多線程端口掃描器詳解_C#教程
- 2022-04-23 冷知識(shí):font-size最小12px的誤區(qū)
- 2025-02-10 window11 系統(tǒng)安裝 yarn
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支