Android 布局崩溃:二进制 XML 文件第 10 行必须提供布局宽度
我很困惑,我已经推断它位于较大布局的合并部分中(编辑谢谢,是的,第 10 行有点明显,第 10 行的文本视图显然需要宽度和高度,但仅使用代码中进一步存在的文本视图没有崩溃,我已将其粘贴到第 #10 行)
<merge xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/frameLayoutLatest">
<LinearLayout android:id="@+id/subLinLayoutHeader" android:orientation="horizontal" android:layout_gravity="center_horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:src="@drawable/layouttriangle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal"></ImageView>
</LinearLayout>
<TableLayout android:id="@+id/subLinLayout" android:layout_below="@id/subLinLayoutHeader" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical">
<ScrollView android:layout_width="wrap_content" android:layout_height="wrap_content">
<!-- list view goes here -->
<TextView android:layout_gravity="center_vertical|center_horizontal" android:text="Dummy text" android:textColor="#ffffff" android:textSize="16dip"></TextView>
</ScrollView>
</LinearLayout>
</TableRow>
<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:layout_gravity="center_vertical|center_horizontal" android:text="Latest Articles" android:textColor="#ffffff" android:textSize="16dip"></TextView>
</TableRow>
</TableLayout>
<ScrollView android:layout_width="wrap_content" android:layout_height="wrap_content">
<!-- list view goes here -->
</ScrollView>
</LinearLayout>
</TableRow>
</TableLayout>
沃尔多在哪里?
I'm stumped, I've already deduced it to being within this merge section of the larger layout (edit thanks, yes line #10 was sort of obvious, the textview on line 10 clearly needed the width and height, but there were no crashes using just textview that exists further in the code, which I had pasted into line #10)
<merge xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/frameLayoutLatest">
<LinearLayout android:id="@+id/subLinLayoutHeader" android:orientation="horizontal" android:layout_gravity="center_horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:src="@drawable/layouttriangle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal"></ImageView>
</LinearLayout>
<TableLayout android:id="@+id/subLinLayout" android:layout_below="@id/subLinLayoutHeader" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical">
<ScrollView android:layout_width="wrap_content" android:layout_height="wrap_content">
<!-- list view goes here -->
<TextView android:layout_gravity="center_vertical|center_horizontal" android:text="Dummy text" android:textColor="#ffffff" android:textSize="16dip"></TextView>
</ScrollView>
</LinearLayout>
</TableRow>
<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:layout_gravity="center_vertical|center_horizontal" android:text="Latest Articles" android:textColor="#ffffff" android:textSize="16dip"></TextView>
</TableRow>
</TableLayout>
<ScrollView android:layout_width="wrap_content" android:layout_height="wrap_content">
<!-- list view goes here -->
</ScrollView>
</LinearLayout>
</TableRow>
</TableLayout>
Where's waldo?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当然是在 10 号线:)
您的代码不提供 TextView 的layout_height 或layout_width。每个 xml 元素都需要两者。
这是你的代码:
尝试这个(或使用 match_parent 而不是 wrap_content)
编辑来解释第二个 TextView 的行为
好吧,我今天学到了一些新东西。
根据 TableRow 文档,
这就是它没有抛出错误的原因。
On line 10 of course :)
Your code doesn't supply a layout_height or a layout_width for the TextView. Both are required for every xml element.
This is your code:
Try this instead (or use match_parent instead of wrap_content)
EDIT to explain second TextView's behavior
Well, I learned something new today.
According to the TableRow documentation,
That's why it didn't throw an error.
该文件第 10 行的 ScrollView 中的 TextView 需要布局高度和布局宽度属性,以便系统知道您希望 TextView 的尺寸。如果您不确定从哪里开始,只需从包含它的 ScrollView 中复制两个属性即可。
Your TextView in the ScrollView of line 10 of this file requires a layout_height and layout_width attribute so the system will know the dimensions you would like your TextView to be. If you're not sure where to start just copy the two attributes from the ScrollView that contains it.
错误提示还不够清楚吗?缺少布局宽度(两个
TextView
),如果您修复此问题,您的问题可能会得到解决。Isn’t the error message clear enough? Something is missing a layout width (the two
TextView
), your problem will probably be fixed if you fix this.