I have a very difficult problem here, have tried all did I can find but it still going nowhere.
I need something like this:
A progressBar
with a text with the progress data inside of it, this text can be outside progress level if it doesn't fit on, but in if it does(get it).
Also a flag with the progress percent, exactly under progress level(the real problem).
Sample:
https://dl.dropboxusercontent.com/u/7675841/orange.png
For more samples change "orange.png" by "red.png" and "green.png".
I did something like this: http://blog.mediarain.com/2011/04/android-custom-progressbar-with-rounded-corners/
Adding a TextView
for the text in the progressBar
:
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<RelativeLayout
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp" >
<ImageView
android:id="@+id/track_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/app_name"
android:minHeight="25dp" />
<ImageView
android:id="@+id/progress_drawable_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:contentDescription="@string/app_name"
android:minHeight="25dp" />
<TextView
android:id="@+id/progress_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textColor="#FFF"
android:textSize="14sp"
android:textStyle="bold" />
</RelativeLayout>
And for set the text in/out the progress I did this:
double percent = (double) value / (double) max;
int level = (int) Math.floor(percent * 10000);
drawable.setLevel(level);
double pixelLevel = percent * progressDrawableImageView.getWidth();
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) txt
.getLayoutParams();
if (pixelLevel - 20 < bounds.width()) {
params.leftMargin = (int) pixelLevel + 20;
} else {
params.leftMargin = (int) pixelLevel - bounds.width() - 10;
}
txt.setLayoutParams(params);
This works beautiful but, doesn't work for the percent flag. Or at least doesn't works on all screen sizes and densities.
The proyect: "same dropbox link"/RoundedProgressSampleCustom.zip
Thank You for help me.
PS: Sorry for can't post more than 2 links :c