I have a RelativeLayout
containing another relative layout
which has several backgroundColored views inside of it, like this, and continuing with more views:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity
">
<RelativeLayout
android:id="@+id/palette"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:animateLayoutChanges="true">
<View
android:background="@color/purple"
android:tag="@color/purple"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_width="100dip"
android:layout_height="200dip"
android:id="@+id/view1">
</View>
Then I have a seekbar
which when slided iterates over the number of views of the relative layouts
changing the color of them, like this:
@
Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
for (int i = 0; i < mPalette.getChildCount(); i++) {
View child = mPalette.getChildAt(i);
int originalColor = Color.parseColor((String) child.getTag());
int invertedColor = (0x00FFFFFF - (originalColor | 0xFF000000)) |
(originalColor & 0xFF000000);
if (getResources().getColor(R.color.white) != originalColor &&
getResources().getColor(R.color.lightgray) != originalColor) {
int red = (originalColor >> 16) & 0x000000FF;
int green = (originalColor >> 8) & 0x000000FF;
int blue = originalColor & 0x000000FF;
int invR = (invertedColor >> 16) & 0x000000FF;
int invG = (invertedColor >> 8) & 0x000000FF;
int invB = invertedColor & 0x000000FF;
child.setBackgroundColor(Color.rgb(
(int)(red + (invR - red) * (progress / 100f)), (int)(green + (invG - green) * (progress / 100f)), (int)(blue + (invB - blue) * (progress / 100f))));
child.invalidate();
}
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
That runs smoothly and without problems.
What I want to achieve is to slide that seekBar
automatically by using a ToggleButton "auto" in order to view the colors changing while changing the progress of the seekbar
from 0 to 100, but what actually happens with my code is that it waits until the cycle is completed, and only then the views are updated when the seekbar hits 100 (and it hits it directly without stepping to it), my code for this is this:
public void autoToggle(View view) throws InterruptedException {
SeekBar seekBar=(SeekBar)findViewById(R.id.seekBar);
boolean on = ((ToggleButton) view).isChecked();
if(on){
mPalette = (RelativeLayout) findViewById(R.id.palette);
for (int i =0;i<10;i++){
seekBar.setProgress(i);
mPalette.requestLayout();
Thread.sleep(10);
}
}
else
seekBar.setProgress(0);
}
I have added the mPalette.requestLayout()
method to see if it updated but neither did it.