我被难住了,我已经推断它位于较大布局的合并部分中(编辑谢谢,是的,第 10 行有点明显,第 10 行的 TextView 很明显需要宽度和高度,但是仅使用代码中进一步存在的 TextView (我已将其粘贴到第 #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>
沃尔多在哪里?
最佳答案
当然是在第 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.
这就是它没有抛出错误的原因。
关于Android布局崩溃: Binary XML file line #10 must supply a layout width,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6682475/