您的位置:首页 > 其它

tabhost切换标签:Log中出现You must supply a layout_width attribute的解决方法

2015-04-16 10:45 435 查看
谷歌、百度该问题,发现,除非是真的忘记添加layout_height或者layout_width属性值,对于布局文件没有语法问题但又难以发现问题所在的情况,从自己的经历和一个帖子的说明看到,该错误多半是由于忘记在XML中添加某个属性的长度值。

我遇到的情况,在布局中有如下的长度引用:

android:layout_marginTop ="@dimen/dial_number_bn_top"

但是并没有在对应dpi文件夹的dimens.xml中定义该属性值,因此出错。另外,缺少一些图片资源可能也会引起该错误。

<resources>

<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>

</resources>

http://blog.sina.com.cn/s/blog_76721b120101ai5j.html
另:

<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" 这一句,就会报错。具体原因待查中。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐