按比例缩放动作栏背景图像

时间:2014-04-23 19:10:18

标签: java android eclipse styles android-actionbar

我在我的Android应用程序中使用ActionBar,并自定义每个选项卡,我将一个背景图像与ActionBar相提并论,其内容如下:

在我的手机上看起来很不错,但在其他手机上,它看起来很压扁。如何根据背景比例按比例缩放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&x的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 个答案:

答案 0 :(得分:-1)

您可以使用scaleType(http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

执行此操作

您使用ImageView而不是背景将其作为第一个布局元素并为其指定android: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

相关问题