《第一行代码》百分比布局问题解决

步骤
1、在app/build_gradle中dependencies 类中

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'
    implementation 'androidx.percentlayout:percentlayout:1.0.0'//新加的
}

2、在activity_main中

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/button1"
        android:text="Button 1"
        android:layout_gravity="left|top"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_widthPercent="50%"
        app:layout_heightPercent="50%"/>
 </androidx.percentlayout.widget.PercentFrameLayout>

3效果图
在这里插入图片描述
4、总结
我太难了 ,整了大半天。查各种,归结原因是现在以及迁移到androidx上了,郭大神的代码需要找androidx对应的映射。
这篇博文给我了解决办法,感谢!
https://www.cnblogs.com/hbuwyg/p/11173649.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值