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

步骤
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

发布了24 篇原创文章 · 获赞 9 · 访问量 2755

猜你喜欢

转载自blog.csdn.net/fancyZT/article/details/102451325
今日推荐