indeterminateProgressBar在动作条造型 - 填充问题 [英] indeterminateProgressBar in ActionBar styling - padding issue

查看:369
本文介绍了indeterminateProgressBar在动作条造型 - 填充问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个不确定的进度条,我的动作条(使用ActionBarSherlock)内。一切正常,但我希望它是小的进度条。我用下面的风格:

I want to put an indeterminate progress bar inside my ActionBar (using ActionBarSherlock). Everything works, but I want it to be the small progress bar. I use following style:

<style name="IndeterminateProgress" parent="@android:style/Widget.ProgressBar.Small">
    <item name="android:progressBarPadding">32dp</item>
    <item name="progressBarPadding">32dp</item>
    <item name="android:itemPadding">32dp</item>
    <item name="itemPadding">32dp</item>
</style>


<style name="Widget.Styled.ActionBar.Tiles" parent="Widget.Sherlock.Light.ActionBar">
    <item name="android:indeterminateProgressStyle">@style/IndeterminateProgress</item>
    <item name="android:progressBarPadding">32dp</item>
    <item name="progressBarPadding">32dp</item>
    <item name="android:itemPadding">32dp</item>
    <item name="itemPadding">32dp</item>
</style>

现在的问题是,我不能设置上的进度条填充。正如你可以在上面看到的,我已经试过了各种可能的组合 itemPadding progressBarPadding 等。

结果总是一样的:

The result is always the same:

任何想法?

推荐答案

我发现的适当的大小和填充一个可行的解决方案如何设置不确定进度条。我的解决方案不使用的解决方法与setActionView()。这是解决方案,内置的进度条功能,母语操作栏(ActionBarSherlock)的支持。进度条启用/通过的 setProgressBarIndeterminateVisibility(布尔)的方法禁用。我测试了它在Android上2,3,4和LDPI,MDPI,xhdpi。

I found a working solution how to set indeterminate progress bar with proper size and padding. My solution doesn't use workaround with setActionView(). It is solution for built-in progress bar functionality, supported by native action bar (ActionBarSherlock). Progress bar is enabled/disabled via setProgressBarIndeterminateVisibility(boolean) method. I tested it on Android 2, 3, 4 and ldpi, mdpi, xhdpi.

AndroidManifest.xml中:

AndroidManifest.xml:

<application
    ...
    android:theme="@style/Theme.Example">

/res/values​​/styles.xml:

/res/values/styles.xml:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    ...

    <style name="Theme.Example" parent="Theme.Sherlock">
        <item name="actionBarStyle">@style/Example.ActionBar</item>
        <item name="android:actionBarStyle">@style/Example.ActionBar</item>
    </style>

    <style name="Example.ActionBar" parent="Widget.Sherlock.ActionBar">
        <item name="indeterminateProgressStyle">@style/Example.ActionBar.IndeterminateProgressBar</item>
        <item name="android:indeterminateProgressStyle">@style/Example.ActionBar.IndeterminateProgressBar</item>
    </style>

    <style name="Example.ActionBar.IndeterminateProgressBar" parent="@android:style/Widget.ProgressBar.Large.Inverse">
        <item name="android:indeterminateDrawable">@drawable/layer_list_ab_indeterminate_progress_bar</item>
        <item name="android:minWidth">@dimen/ab_indeterminate_progress_bar_size</item>
        <item name="android:maxWidth">@dimen/ab_indeterminate_progress_bar_size</item>
        <item name="android:minHeight">@dimen/ab_indeterminate_progress_bar_size</item>
        <item name="android:maxHeight">@dimen/ab_indeterminate_progress_bar_size</item>
    </style>
</resources>

/res/drawable/layer_list_ab_indeterminate_progress_bar.xml:

/res/drawable/layer_list_ab_indeterminate_progress_bar.xml:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <!--
        /res/drawable-mdpi/ab_indeterminate_progress_bar asset is taken from
        /sdk/platforms/android-18/data/res/mdpi/spinner_white_48.png
        and its content (optical square) is resized to ~0.6 (must be even number)

        /res/drawable-mdpi-v14/ab_indeterminate_progress_bar asset is taken from
        /sdk/platforms/android-18/data/res/mdpi/spinner_48_outer_holo.png
        and its content (optical square) is resized to 0.75
        -->
        <rotate
            android:drawable="@drawable/ab_indeterminate_progress_bar"
            android:interpolator="@android:anim/linear_interpolator"
            android:pivotX="50%"
            android:pivotY="50%"
            android:fromDegrees="0"
            android:toDegrees="360" />
    </item>
</layer-list>

/res/values​​/dimens.xml:

/res/values/dimens.xml:

<dimen name="ab_indeterminate_progress_bar_size">48dp</dimen>

最后,我创建了进度条的资产。

Finally I created progress bar assets. I used these two assets from Android SDK:

  • /sdk/platforms/android-18/data/res/mdpi/spinner_white_48.png对于蜂窝及以上
  • /sdk/platforms/android-18/data/res/mdpi/spinner_48_outer_holo.png对于 ICS和新
  • /sdk/platforms/android-18/data/res/mdpi/spinner_white_48.png for Honeycomb and older
  • /sdk/platforms/android-18/data/res/mdpi/spinner_48_outer_holo.png for ICS and newer

要获得的适当的大小和填充,我们需要调整资产。我调整spinner_white_48.png为〜0.6 。对于MDPI,这是28px。它必须是偶数是中心对称的。我只是调整了内容,而不是整个图标。因此,在MDPI图标仍然具有48像素,但其内容(光广场)是小(28px)。您可以轻松地调整内容是这样的:第一个变化图像大小为28px X 28px,然后更改画布大小回到48像素X 48像素。我调整spinner_48_outer_holo.png为 0.75 。您也可以下载资产如下:

To get proper size and padding, we need to resize the assets. I resized spinner_white_48.png to ~0.6. For mdpi, it was 28px. It must be even number to be centrally symmetric. I resized only the content, not the whole icon. So icon in mdpi has still 48px, but its content (optical square) is smaller (28px). You can easily resize the content this way: first change "image size" to 28px X 28px, then change "canvas size" back to 48px X 48px. I resized spinner_48_outer_holo.png to 0.75. You can download the assets below.

为什么我用的蜂窝状和ICS +不同的资产?因为如果我只用霍洛资产,动画是在与蜂窝某些设备有点断断续续。 -

Why do I use different assets for Honeycomb- and ICS+? Because if I'm using only Holo assets, the animation is little bit snatchy on some devices with Honeycomb-.

提示:你可以用一些动画layer_list_ab_indeterminate_progress_bar.xml添加另一个项目。例如标准的全息进度栏所使用2动画与相反的方向和不同程度的范围内。见progress_medium_holo.xml在SDK中。

Tip: you can add another item with some animation to layer_list_ab_indeterminate_progress_bar.xml. For example standard Holo progress bar uses 2 animations with opposite direction and different degrees range. See progress_medium_holo.xml in SDK.

/res/drawable-mdpi/ab_indeterminate_progress_bar.png:

/res/drawable-mdpi/ab_indeterminate_progress_bar.png:

/res/drawable-mdpi-v14/ab_indeterminate_progress_bar.png(此页面上几乎看不到):

/res/drawable-mdpi-v14/ab_indeterminate_progress_bar.png (hardly visible on this page):

/res/drawable-hdpi/ab_indeterminate_progress_bar.png:

/res/drawable-hdpi/ab_indeterminate_progress_bar.png:

/res/drawable-hdpi-v14/ab_indeterminate_progress_bar.png(此页面上几乎看不到):

/res/drawable-hdpi-v14/ab_indeterminate_progress_bar.png (hardly visible on this page):

/res/drawable-xhdpi/ab_indeterminate_progress_bar.png:

/res/drawable-xhdpi/ab_indeterminate_progress_bar.png:

/res/drawable-xhdpi-v14/ab_indeterminate_progress_bar.png(此页面上几乎看不到):

/res/drawable-xhdpi-v14/ab_indeterminate_progress_bar.png (hardly visible on this page):

这篇关于indeterminateProgressBar在动作条造型 - 填充问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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