日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

Android百分比布局被棄用的問(wèn)題

作者:Nianf 更新時(shí)間: 2023-12-06 編程語(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)行了,效果如下:
1

原文鏈接:https://blog.csdn.net/qq_43738932/article/details/126040023

  • 上一篇:沒(méi)有了
  • 下一篇:沒(méi)有了
欄目分類
最近更新