我正在关注Android的教程。第一个教程包括放置文本并将layout_height
设置为match_parent
,如下所示(教程截图):
但是,当我尝试对最新版本的Android studio执行相同操作时,不建议使用此选项。我只能在wrap_content
和match_constraint
之间进行选择。但是,如果我转到XML视图并手动输入值,它就可以正常工作。
为什么呢?这是一个错误吗?或者match_parent
已被弃用?
另外,我有一条可能相关的错误消息
无法找到风格' coordinatorLayoutStyle'在当前主题
答案 0 :(得分:5)
引用the ConstraintLayout
documentation:
重要提示:不建议对ConstraintLayout中包含的小部件使用MATCH_PARENT。可以通过使用MATCH_CONSTRAINT来定义类似的行为,其中相应的左/右或上/下约束被设置为" parent"。
所以,我会认为Android Studio的变化是进一步的" nudge"停止将match_parent
与ConstraintLayout
一起使用。坦率地说,当我尝试它时,我从来没有运气。 match_parent
可用于经典容器类(例如LinearLayout
)或ConstraintLayout
本身的大小。
答案 1 :(得分:3)
这是因为您正在处理约束布局。 如果您的xml布局是线性或相对的,您可以选择。 检查你的xml文件,看看我在推荐什么。
你会看到类似的东西。
"C:\Program Files\nodejs\node.exe" "E:/INSTALL MISHA/stylelint/stylelint-master/bin/stylelint.js" -f json --stdin-filename "..\..\..\..\..\:/Computer science/Web Site/HTML CSS JQuery website codecademy/untitled/style.css"
module.js:549
throw err;
^
Error: Cannot find module 'chalk'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (E:\INSTALL MISHA\stylelint\stylelint-master\lib\cli.js:4:15)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
Process finished with exit code 1
更改布局,您将能够match_parent