【问题标题】:Scale Action Bar background image proportionally按比例缩放操作栏背景图像
【发布时间】:2014-04-23 19:10:18
【问题描述】:

我在我的 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 的 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

【问题讨论】:

    标签: java android eclipse styles android-actionbar


    【解决方案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>
    

    或可绘制的 xml

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-08
      • 1970-01-01
      • 2012-03-06
      • 2016-06-23
      相关资源
      最近更新 更多