java - 当我尝试在 xml 文件中设置布局宽度和高度时出现错误
问题描述
设置布局高度和宽度时,android studio 显示该属性的错误
android:layout_height和android:layout_width分别在这里是不允许的。
并且设置TextView也显示错误:-
此处不允许使用元素 TextView。
我已阅读并尝试了Element LinearLayout is not allowed in CardView的答案, 但没有帮助。
我检查了是否有任何额外的左括号或右括号,但没有。gradle.build 文件有问题吗?我已经检查过,但看起来不错。
这是 activity__main.xml 文件中的代码。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:textSize="20sp" />
</FrameLayout>
这是 build.gradle 的代码
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
defaultConfig {
applicationId "com.android.example.favoritetoys"
minSdkVersion 10
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:25.1.0'
}
解决方案
推荐阅读
- javascript - 汉堡菜单问题 - CSS 和 vanilla JS
- excel - 表单控件点击无响应
- sql - 在备用行上使用 LAG/LEAD 缺少 PK
- css - 添加内部弹性项目会导致弹性项目扩展,尽管图像足够小以适合内部
- c# - 我如何知道取消的异步任务是否完成?
- python - 8.9 LAB:汽车价值 - python
- python-3.x - 循环没有更改目录,但我可以打印出目录-为什么会这样
- cassandra - 什么可能导致我的 cassandra 节点有这么多待处理的任务?
- java - OkHttpClient 将 http URL 重定向到 Https 并给出带有 https URL 的 SSLException
- python - 为什么这个 matplotlib 图中的 x 轴是分开的(以及如何解决这个问题)?