Android 布局崩溃:二进制 XML 文件第 10 行必须提供布局宽度

发布于 2024-11-24 03:13:48 字数 2506 浏览 2 评论 0原文

我很困惑,我已经推断它位于较大布局的合并部分中(编辑谢谢,是的,第 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

如何视而不见 2024-12-01 03:13:48

当然是在 10 号线:)
您的代码不提供 TextView 的layout_height 或layout_width。每个 xml 元素都需要两者。

这是你的代码:

<TextView
android:layout_gravity="center_vertical|center_horizontal"
android:text="Dummy text"
android:textColor="#ffffff"
android:textSize="16dip">
</TextView>

尝试这个(或使用 match_parent 而不是 wrap_content)

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:text="Dummy text"
android:textColor="#ffffff"
android:textSize="16dip">
</TextView>

编辑来解释第二个 TextView 的行为

好吧,我今天学到了一些新东西。
根据 TableRow 文档,

The children of a TableRow do not need to specify the layout_width
and layout_height attributes in the XML file. TableRow always enforces
those values to be respectively MATCH_PARENT and WRAP_CONTENT.

这就是它没有抛出错误的原因。

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:

<TextView
android:layout_gravity="center_vertical|center_horizontal"
android:text="Dummy text"
android:textColor="#ffffff"
android:textSize="16dip">
</TextView>

Try this instead (or use match_parent instead of wrap_content)

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:text="Dummy text"
android:textColor="#ffffff"
android:textSize="16dip">
</TextView>

EDIT to explain second TextView's behavior

Well, I learned something new today.
According to the TableRow documentation,

The children of a TableRow do not need to specify the layout_width
and layout_height attributes in the XML file. TableRow always enforces
those values to be respectively MATCH_PARENT and WRAP_CONTENT.

That's why it didn't throw an error.

滿滿的愛 2024-12-01 03:13:48

该文件第 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.

陌上芳菲 2024-12-01 03:13:48

错误提示还不够清楚吗?缺少布局宽度(两个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文