2014-04-23 52 views
1
使用動作條在我的Android應用程序1m,並自定義每個標籤的

,我把背景圖像behing的動作條,看起來如下:規模操作欄背景圖片按比例

在我手機實際上看起來不錯,但在其他手機上,它看起來非常壓扁。我如何根據背景的比例按比例調整ActionBar?有沒有解決方案?我必須確定修復DPI中的高度,因爲如果我放棄它,ActionBar甚至不會顯示出來。我現在的風格代碼如下:

<style name="MyActionBar" parent="android:Theme.Holo.Light"> 

    <item name="android:backgroundStacked">@drawable/tab_bg</item> 
    <item name="android:adjustViewBounds">true</item> 
    <item name="android:scaleType">fitEnd</item> 
    <item name="android:height">87dp</item> 

</style> 

更新:

我只是不知道哪裏來Mr.T的XML代碼。我使用基本的Android ActionBar,並且我只有一個名爲menu.xml的xml,但是如果我把代碼放入它,沒有任何效果。

我嘗試使用以下方式設置操作欄的風格,但如果不指定android:height參數,操作欄仍然爲0並且不顯示。

<style name="MyActionBar" parent="android:Theme.Light"> 
    <item name="android:backgroundStacked">@drawable/tab_bg</item> 
    <item name="android:layout_width">wrap_content</item> 
    <item name="android:layout_height">wrap_content</item> 
    <item name="android:src">@drawable/tab_bg</item> 
    <item name="android:scaleType">matrix</item> 
</style> 

該操作欄在某些設備上仍然類似於以下內容; http://i.imgur.com/yQN67J3.png

回答

-1

你可能有兩種scaleType(http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

做到這一點,您使用的ImageView,而不是背景把它作爲第一個佈局的元素,並指定機器人:scaleType屬性吧:

<RelativeLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 

    android:src="@drawable/backgrnd" 
    android:scaleType="matrix" /> 

... 

rest layout components here 

... 

</RelativeLayout> 

或drawable xml

+0

我已經更新了這個問題。 –