Android活动二进制XML文件行:必须提供布局宽度属性

Android活动二进制XML文件行:必须提供布局宽度属性,android,android-layout,Android,Android Layout,我已经读过了,但它仍然在这里 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" tools:cont

我已经读过了,但它仍然在这里

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".TaskEditActivity" >

因此,异常
java.lang.RuntimeException:Binary XML文件行#34:必须提供布局宽度属性。

属性也在那里。。。
解决方案?

很清楚。子元素缺少布局宽度属性。

您的问题不在该布局元素中,而是在内部元素中,请查看第34行。还有一个用户界面元素缺少layout\u width属性。

对于我来说,在我的layout.xml文件中,我有

<ImageView
    android:id="@+id/row_1_col_0"
    android:layout_width="@string/default_picture_size"
    android:layout_height="@string/default_picture_size"
    android:layout_weight="1"
    android:background="@drawable/tile"
    android:onClick="mClickMethod" >
</ImageView>


一切顺利

对我来说,它在我的一个视图组(scrollview)上有一个额外的属性:

之后,我忘了将EditText的角色设置更改为TextView:


原因:java.lang.ClassCastException:android.support.v7.widget.AppCompatTextView无法强制转换为android.widget.EditText此外,我建议检查您的维度。您可能有以dimens为单位的布局宽度,您转到它,您有像“150”这样的值,而不是“150dp”(缺少dp)也会导致这种情况(这是我的情况)

我有一个给定宽度的尺寸,但它不存在于默认的dimens.xml中


以防所有的解决方案都不起作用
清理项目
->
运行

干杯

如果在片段/活动上应用或不应用正确的主题,则可能发生这种情况

例如,Leanback的
OnboardingSupportFragment
需要
主题.Leanback.Onboarding
,您必须将其应用于清单
android:Theme=“@style/Theme.Leanback.Onboarding”
中的活动或覆盖
OnProviderTheme()


清理和重建?并发布整个布局我确信布局中的一个子视图将缺少布局宽度属性。。请交叉检查,您能发布您的整个XML文件吗?您看到了哪个设备?您看到了哪个设备?这不是很奇怪,并且与最小宽度配置完全矛盾吗。它应该从320 dp中正确地选择。我的宽度是以迪蒙斯为单位的,但一切都是正确的,而且它偶尔也会发生,不总是发生。谢谢你救了我一天。我花了2天的时间搜索这个错误谢谢你的输入。这是一个很难发现的仅运行时错误,也很难注意到。
<ImageView
    android:id="@+id/row_1_col_0"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/tile"
    android:onClick="mClickMethod" >
</ImageView>
android:layout_width="@string/default_picture_size"
android:layout_height="@string/default_picture_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
res/
   values-w320dp/
          dimens.xml -> ring_radius=5dp
   values/
          dimens.xml -> missing ring_radius
@Override
public int onProvideTheme() {
    return R.style.Theme_Leanback_Onboarding;
}