自定义进度栏无法在某些设备上运行

时间:2013-12-24 11:40:30

标签: android android-progressbar nine-patch xml-drawable

编辑:

我创建了一个仅使用9个补丁drawable的进度条和另一个依赖于剪辑drawable的进度条,如下所示,我已经在github上发布了这两个项目。使用Sony设备的人可以测试项目并告诉我哪一个适用于他们(它不工作的设备是Xperia M)。我在评论中发布了链接,或者你可以告诉我在哪里可以免费在线测试。

此代码适用于我的Galaxy Nexus,但它似乎无法在某些设备上运行...
我使用以下xml文件创建了自定义进度条:

     <?xml version="1.0" encoding="utf-8"?>
     <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- Background is a rectangle with a solid black fill -->

    <item android:id="@android:id/background">
        <shape android:shape="rectangle">
            <corners android:radius="8dp"/>
            <solid android:color="#000000"/>  
            <stroke android:width="4dp"
                        android:color="#ffffff"/>

        </shape>
    </item>

    <!-- The secondary progress,a gradient with a stroke and a padding -->
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape android:shape="rectangle">
                <corners android:radius="8dp"/>
                <gradient 
                    android:startColor="#6c006d"
                    android:centerColor="#e100e0"
                    android:endColor="#ff28ff"
                    android:angle="0"
                    android:type="linear"
                    />
                 <stroke android:width="4dp"
                        android:color="#ffffff"/>

            </shape>
        </clip>
    </item>

    <item android:id="@+id/progress">
   <shape android:shape="rectangle">
        <corners android:radius="8dp"/>
        <stroke android:width="4dp"
                    android:color="#ffffff"/>
    <scale android:scaleWidth="100%"
           android:drawable="@drawable/untitled_1"/></shape>        
       </item>

      </layer-list>

这是我用来在XML中定义ProgressBar的XML:

 <ProgressBar android:id="@+id/progressbar_update"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:max="100"
            android:progressDrawable="@drawable/custom_progressbar"
            android:layout_marginRight="5dp"
            style="@android:style/Widget.ProgressBar.Horizontal"
            />   

我的两个使用索尼智能手机的朋友报告了应用程序没有显示进度或在进度条加载时抛出错误的问题。我使用片段中的AsyncTask更新进度条,该片段保留了它的实例,如下所示:

 @Override
public void onProgressUpdate(Bitmap bitmap,int progress) {
    // TODO Auto-generated method stub
    int size = (int) ( bitmap .getHeight() * (1024.0 / bitmap .getWidth()) );
    Bitmap scaled = Bitmap.createScaledBitmap(bitmap , 1024, size, true);
    img_currentOp.setImageBitmap(scaled);
    updatebar.setProgress(progress);
}

建议使用此组合的模式here
这是我用于创建进度条的图像:Image for displaying progress

1 个答案:

答案 0 :(得分:0)

我猜你在角标签中提到的半径不会起作用..!

<corners android:radius="8dp"/>

我在版本2.X.X;

的设备中也遇到了问题

使用NinePatch图像代替drawable [如果可能]