您必须提供layout_width属性异常

时间:2011-04-16 10:06:04

标签: android-layout

我的布局在底部的前2个按钮上有标题,一些文本视图和两者之间的编辑文本。我愿意将这些EditText和Text视图放在滚动视图中,这样我就可以滚动并且EditText不会隐藏在键盘后面。

这是我的XML文件,我很抱歉它有点冗长,但是请看看这个,让我知道这有什么不对。我总是得到 java.lang.RuntimeException:二进制XML文件行#73:您必须提供layout_width属性。 我尝试过很多方法来改变宽度和高度,但我总是得到这个错误。

XML文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:gravity="center_horizontal">
        <!-- Title(Preview) Background and  Text-->
        <RelativeLayout
            android:id="@+id/previewBG"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/title_bg">

            <TextView
                android:id="@+id/previewTxt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/addDevicesTittle"
                android:textSize="24sp"
                android:typeface="sans"
                android:textColor="#ffffff"
                android:layout_centerInParent="true"
            >
            </TextView>
        </RelativeLayout>
        <!--  Title(Preview) Background and  Text End -->
                <!--  Buttons  -->
        <LinearLayout
        android:id="@+id/Buttons" 
        android:layout_width="fill_parent" 
        android:layout_height="60dip"
        android:layout_alignParentBottom="true"
        android:background="@color/COL_BTNBG">      

            <LinearLayout
                android:id="@+id/btnRefresh_part"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="6dip">


                <Button
                    android:id="@+id/btnSave"
                    android:layout_width="fill_parent"
                    android:layout_height="49dip"
                    android:text="@string/btn_manual_save"
                    android:textSize="24sp"
                    android:typeface="sans"
                    android:textColor="@color/COL_WHITE"
                    android:layout_weight ="1"
                    android:background="@+drawable/button_02"

                >
                </Button>
                <Button
                    android:id="@+id/btnCancel"
                    android:layout_width="fill_parent"
                    android:layout_height="49dip"
                    android:text="@string/btn_manual_cancel"
                    android:textSize="24sp"
                    android:typeface="sans"
                    android:textColor="@color/COL_WHITE"
                    android:layout_weight ="1"
                    android:background="@+drawable/button_02"

                >
                </Button>   

            </LinearLayout>
        </LinearLayout>
        <!--  Buttons End -->

        <ScrollView
            android:id="@+id/scrollView"
            android.layout_width="50dip"
            android.layout_height="300dip" 
            android:layout_below="@+id/previewBG"
            >

            <RelativeLayout
                android:id="@+id/Data" 
                android:layout_width="fill_parent" 
                android:layout_height="fill_parent"
                android:isScrollContainer="true">

                <TextView
                    android:id="@+id/domain_view"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:text="@string/txtDomain"
                    android:gravity="left"
                    android:textAppearance="?android:attr/textAppearanceMedium" 
                    android:layout_marginLeft="20dip" 
                    android:layout_marginRight="20dip"
                    android:layout_alignParentTop = "true" 
                    android:layout_marginTop="10dip"/>

                <EditText
                    android:id="@+id/domain_edit"
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent"
                    android:layout_marginLeft="20dip"
                    android:layout_marginRight="20dip"
                    android:scrollHorizontally="true"
                    android:singleLine ="true"
                    android:autoText="false"
                    android:hint ="@string/txtDomainExample"
                    android:capitalize="none"        
                    android:gravity="fill_horizontal"
                    android:layout_below = "@+id/domain_view"                   
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <TextView
                    android:id="@+id/ip_view"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:text="@string/manual_IP"
                    android:gravity="left"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:layout_below = "@+id/domain_edit"                   
                    android:layout_marginLeft="20dip" 
                    android:layout_marginRight="20dip"                   
                    android:layout_marginTop="10dip"/>


                <EditText
                    android:id="@+id/ip_edit"
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent"
                    android:layout_marginLeft="20dip"
                    android:layout_marginRight="20dip"
                    android:scrollHorizontally="true"
                    android:singleLine ="true"
                    android:autoText="false"
                    android:hint ="@string/enter_IP_address"
                    android:capitalize="none"        
                    android:gravity="fill_horizontal"
                    android:layout_below = "@+id/ip_view"                   
                    android:textAppearance="?android:attr/textAppearanceMedium" />


                <TextView
                    android:id="@+id/user_view"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:text="@string/txtUserName"
                    android:gravity="left"                  
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:layout_below = "@+id/ip_edit" 
                    android:layout_marginLeft="20dip" 
                    android:layout_marginRight="20dip" 
                    android:layout_marginTop="10dip"/>

                <EditText
                    android:id="@+id/user_edit"
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent"
                    android:layout_marginLeft="20dip"
                    android:layout_marginRight="20dip"
                    android:scrollHorizontally="true"       
                    android:hint ="@string/txtUserNameExample"
                    android:singleLine ="true"
                    android:autoText="false"
                    android:capitalize="none"
                    android:gravity="fill_horizontal"
                    android:layout_below = "@+id/user_view"                 
                    android:textAppearance="?android:attr/textAppearanceMedium" />


                <TextView
                    android:id="@+id/password_view"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:text="@string/txtPassword"
                    android:gravity="left"                  
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:layout_below = "@+id/user_edit" 
                    android:layout_marginLeft="20dip" 
                    android:layout_marginRight="20dip" 
                    android:layout_marginTop="10dip"/>

                <EditText
                    android:id="@+id/password_edit"
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent"
                    android:layout_marginLeft="20dip"
                    android:layout_marginRight="20dip"
                    android:scrollHorizontally="true"
                    android:hint ="@string/txtPasswordExample"
                    android:singleLine ="true"
                    android:autoText="false"
                    android:capitalize="none"
                    android:gravity="fill_horizontal"                   
                    android:password = "true"
                    android:layout_below = "@+id/password_view"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                 </RelativeLayout>   
        </ScrollView>

</RelativeLayout>

2 个答案:

答案 0 :(得分:9)

你的ScrollView有android.layout_width而不是android:layout_width ...类似layout_height

观察点而不是冒号

这可能是你的问题

答案 1 :(得分:0)

Sachin的回答是针对您的问题的解决方案。我只是想说,在Eclipse中,通过从XML视图切换到Graphical Layout选项卡,Eclipse试图解析XML,发现它的问题并建议快速修复,这就像魔术一样。不需要在模拟器中启动应用程序只是为了在堆栈跟踪爆炸时看到它。