1. 程式人生 > >You must supply a layout_width attribute. 錯誤解決

You must supply a layout_width attribute. 錯誤解決

佈局檔案如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="right"
    android:orientation="vertical"
    android:visibility="visible" >

    <LinearLayout
        android:layout_width="310dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:animateLayoutChanges="false"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/LinearLayout_dz"
            android:layout_width="match_parent"
            android:layout_height="37dp"
            android:orientation="horizontal"
            android:visibility="visible" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView" />



        </LinearLayout>
    </LinearLayout>

</LinearLayout>

今天在編輯android佈局檔案時,後臺提示以下錯誤:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pubproject/com.example.pubproject.MainActivity}: java.lang.RuntimeException: Binary XML 

file line #23: You must supply a layout_width attribute.

經反覆試驗:原因是TextView只要缺少  android:layout_width="wrap_content" 這一句,就會報錯。具體原因待查中。