为什么我不应该设置一个样式layout_width和layout_height? [英] Why shouldn't I set layout_width and layout_height in a style?

查看:386
本文介绍了为什么我不应该设置一个样式layout_width和layout_height?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有很多作为项目标签TextViews的,我以为我可以提取一切的共同关于他们成风格,在布局只使用

If I have a lot of TextViews serving as item labels, I thought I could extract everything that's common about them into a style, and in the layout use only

<TextView style="@style/label" android:text="Foo"/>
<TextView style="@style/label" android:text="Bar"/>

与风格,如:

<style name="label">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
</style>

但是当我这样做,它工作正常的仿真器和设备,但Android的XML编辑器抱怨说&LT;&TextView的GT;不设置所需layout_height属性。
是否有关于它为什么报告此警告的一些原因是什么?

But when I do this, it works fine on emulator and device, but the Android XML editor complains that "<TextView>" does not set the required layout_height attribute. Is there some reason on why it is reporting this warning?

推荐答案

您是否尝试过清理项目?

Have you tried to clean the project?

我也使用在宽度和长度的一些XML文件同样的事情。
这里有一个例子我的应用程序时,您可以看看:

I am using also the same thing on some XML files for the width and the length. Here is an example working on my app, you can have a look:

<TextView
    android:id="@+id/viewdescription"
    android:textIsSelectable="true"
    android:layout_below="@+id/rating_bar_view"
    android:minLines="8"
    style="@style/description" />

和XML:

<style name="description">
   <item name="android:layout_gravity">center_horizontal</item>
   <item name="android:inputType">textMultiLine</item>
   <item name="android:layout_width">fill_parent</item>
   <item name="android:layout_height">wrap_content</item>     
   <item name="android:textSize">14sp</item>
   <item name="android:textColor">@color/Black</item>
   <item name="android:layout_marginRight">8dp</item>
   <item name="android:layout_marginLeft">8dp</item>

这篇关于为什么我不应该设置一个样式layout_width和layout_height?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆