編集:
以下に投稿したように、9 パッチのドローアブルのみを使用するプログレス バーと、クリップのドローアブルに依存する別のプログレス バーを作成しました。両方のプロジェクトを投稿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"
/>
ソニーのスマートフォンを使用している 2 人の友人が、アプリが進行状況を表示しない、またはプログレスバーが読み込まれるはずのときにエラーをスローするという問題を報告しました。
@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);
}
この組み合わせを使用するためのパターンは、ここ
で提案されました。これは、プログレス バーの作成に使用した画像です。