2010-01-07 150 views
5

我认为更多“全局”样式总是被更多“本地”样式所覆盖。例如,如果我将所有按钮重新定义为textSize = 40dip(将该样式应用为应用程序的主题),然后将另一个样式应用于指定textSize = 10dip的特定按钮,那么该特定Button应该获得10dip textSize。样式,minHeight/maxHeight:我无法让maxHeight覆盖主题minHeight

这就是它的工作原理,通常。但是,当涉及到maxHeight时。这里是场景:

在我的 styles.xml我有一个样式,我继承了默认的Button并更改textSize和minHeight,然后另一个样式设置了一些其他值(但也从Button继承),就像这个:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
<style name="Button" parent="@android:style/Widget.Button"> 
    <item name="android:textSize">26dip</item> 
    <item name="android:minHeight">60dip</item> 
</style> 

<style name="ButtonHeader" parent="@android:style/Widget.Button"> 
    <item name="android:textSize">18dip</item> 
    <item name="android:minWidth">70dip</item> 
    <item name="android:maxHeight">10dip</item> 
</style> 
</resources>  

我将第一个Style应用为我的Activity的一个主题,它使所有按钮变大(minHeight = 60dip)。但我有一个“标题”(其中有一些其他按钮),我不想拥有60dip的minHeight,而对于这些按钮,我想使用 ButtonHeader,将maxHeight设置为10dip。

在我 header.xml它看起来像这样:

<Button style="@style/ButtonHeader" android:text="UPP" android:id="@+id/Header_Button_UPP" android:layout_width="wrap_content" android:layout_height="wrap_content" ></Button> 
<Button style="@style/ButtonHeader" android:text="ALT" android:id="@+id/Header_Button_ALT" android:layout_width="wrap_content" android:layout_height="wrap_content" ></Button> 
<Button style="@style/ButtonHeader" android:text="NAV" android:id="@+id/Header_Button_NAV" android:layout_width="wrap_content" android:layout_height="wrap_content" ></Button> 
<Button style="@style/ButtonHeader" android:text="HIS" android:id="@+id/Header_Button_HIS" android:layout_width="wrap_content" android:layout_height="wrap_content" ></Button> 

我specificly造型的按钮,覆盖了 “全球” 的主题。它在一些地方起作用;这些标题按钮的textSize被正确设置为18dip,但maxHeight被忽略 - 这些按钮的高度也增加到60dip。

如果我在ButtonHeader的样式中设置android:minHeight =“100dip”,那么标题中的按钮将增加到100dip,覆盖主题。 但是,如上所述,当我有android:maxHeight时,没有任何反应。

我错过了什么?

+0

没有人有线索? =) – Ted 2010-01-08 21:02:40

回答

5

应该不是你的风格ButtonHeader覆盖minHeight属性?看起来你最终得到了minHeight = 60dp和maxHeight = 10dp,minHeight获胜。如果你明确地将minHeight设置为别的东西,你就不应该有这个问题。

+0

好吧,我需要像你说的那样重写minheight =)不知道为什么我没有想到这一点。我有点认为,重写maxHeight应该这样做。听起来有点合理。不管怎样,回答OK,积分奖励=) – Ted 2010-01-15 23:22:38

0

我underestand你有按钮(按钮 - HeaderButton)2种不同的建筑风格,在HeaderButton样式设置minHieght和MaxHeight(最大高度isworking)现在了minHeight脸的问题,

我执行你的代码,发现你的了minHeight不适合18dip TEXTSIZE,所以你要么减少你的号数或增加大小了minHeight

让我知道,什么发生在你身上

+0

嘿!当然,我知道ButtonHeader中的“maxHeight”太小了。我尝试了各种价值观,没有任何帮助。 “主题”覆盖了ButtonHeader风格,并使按钮(在标题中)更大,不管我在ButtonHeader中放置了什么样的maxHeight =( – Ted 2010-01-11 17:12:09