我正在开发自定义进度条,它将逐个淡出,因此它让我们感觉像是在移动循环进度。为此我已经声明了这个xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/customsearcl_ll"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="15dp"
android:orientation="vertical" >
<ImageView
android:id="@+id/circle1_imgv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:src="@drawable/circle_shape_big_custom_search" />
<ImageView
android:id="@+id/circle2_imgv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:src="@drawable/circle_shape_big_custom_search" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/circle3_imgv"
android:layout_width="wrap_content"
android:layout_height="72dp"
android:src="@drawable/circle_shape_big_custom_search" />
<ImageView
android:id="@+id/circle4_imgv"
android:layout_width="wrap_content"
android:layout_height="72dp"
android:src="@drawable/circle_shape_big_custom_search" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="15dp"
android:orientation="vertical" >
<ImageView
android:id="@+id/circle5_imgv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:src="@drawable/circle_shape_big_custom_search" />
<ImageView
android:id="@+id/circle6_imgv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:src="@drawable/circle_shape_big_custom_search" />
</LinearLayout>
当您看到上面的xml文件时,您会感觉到没有任何
android:alpha
被调用。所以改变alpha我声明图像如下
image1 = (ImageView)findViewById(R.id.circle3_imgv);
image2 = (ImageView)findViewById(R.id.circle5_imgv);
image3 = (ImageView)findViewById(R.id.circle6_imgv);
image4 = (ImageView)findViewById(R.id.circle4_imgv);
image5 = (ImageView)findViewById(R.id.circle2_imgv);
image6 = (ImageView)findViewById(R.id.circle1_imgv);
i = 0;
alpha = (float).8;
imaArray = new ImageView[] {image1 ,image2,image3,image4,image5, image6};
之后将计时器声明为
final CountDownTimer Counter1 = new CountDownTimer(500 , 500) {
public void onTick(long millisUntilFinished) {
changeAlpha();
}
public void onFinish() {
Counter1.start();
}
};
然后在onCreate()里面调用Counter1.start();因此它调用计数器和内部计数器称为changeAlpha()方法。
void changeAlpha(){
imaArray[i].setAlpha(alpha);
alpha = (float) (alpha - .2);
i++;
if(i ==5){
i =0;
alpha = (float) .8;
}
}
但问题是它改变了我们绘制的alpha但只有一次意味着它不会一次又一次地旋转。它完全360度下降它的停止,但期望是通过alpha改变n-次旋转这个图像。它将看起来如下所示