Wednesday, September 25, 2013

[android help] Setting progressbar's progressDrawable


Setting progressbar's progressDrawable



Im trying to create a custom progressbar. Im trying to only make half of the progressbar filled with blue color. But the result is that the whole bar gets filled eventhough i set the progress to be half of the maximum! This is my code:



xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

android:id="@+id/batteryProgressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignParentRight="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="26dp"/>


and the custom class:



public class BatteryProgressBar extends ProgressBar {

public BatteryProgressBar(Context context) {
super(context);
init();

}

public BatteryProgressBar(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

public BatteryProgressBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}

private void init() {
setProgressDrawable(getResources().getDrawable(R.drawable.blue));
setMax(100);
setProgress(50);
}


}


and my blue color comes from









Why is the whole bar filled when im only setting it to be 50% filled?


Thanks!



Read more

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...