关于百分比布局Design页面 :The following classes could not be found: android.percentlayout.widget.PercentRelativeLayout的解决方法
配置百分比布局
根据安卓第一行代码中的方法在app->build.gradle闭包中添加一行代码,只是这里需要注意点问题:
- 书上这样写在dependencies闭包中添加如下内容 compile
‘com.android.support:percent:24.2.1’ 这里要注意 Android
Studio提示说compile过时以被implementation取代,好吧这不是大问题,但是要注意下面的
敲黑板
- 如果你和我一样使用了现在来说较新的API 那么你要写成这样implementation’androidx.percentlayout:percentlayout:1.0.0’
这是因为com.android.support下面的依赖到了28.0.0之后就不再维护了, 后面迁移到Androidx
具体可以看这里
https://developer.android.com/jetpack/androidx?hl=zh-cn
官方说的很清楚:
Existing packages, such as the Android Support Library, are being refactored into AndroidX.
Although Support Library versions 27 and lower are still available on Google Maven,
all new development will be included in only AndroidX versions 1.0.0 and higher.
在gradle配置好了的情况下你可能会出现这样的问题
点击右上角的警示标志
The following classes could not be found: android.percentlayout.widget.PercentRelativeLayout
解决方法如下
你的xml大概是这样写的:
**现在尝试将percentlayout这一行改成如下这样: **
androidx.percentlayout.widget.PercentRelativeLayout
或者你直接打一个"ap" 在出来的选项里找百分比布局的那个, IDE给你弄出来准没问题…
好啦 大功告成