我已使用以下布局实现了加载微调器图标:
__declspec
但是这会使用默认的Android微调器。我想用我从preloaders.net得到的加载图标替换微调器,如下所示:
如何使用此自定义微调器替换默认的Android微调器?
答案 0 :(得分:1)
这是我在项目中使用的:
<ProgressBar
android:id="@+id/updateProgressBar"
android:layout_width="40dp"
android:layout_height="40dp"
android:drawingCacheQuality="high"
android:indeterminateDuration="2000"
android:indeterminateDrawable="@drawable/splash_spinner"
/>
只需使用自定义图片覆盖indeterminateDrawable
答案 1 :(得分:1)
如果您想旋转PNG图像并充当进度栏,则只需创建一个rotate
布局,然后在该布局上插入PNG
在res
-> drawable
内,创建一个名为rotate.xml
的新文件。
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/pokeball" <--Insert your image here
android:fillAfter="false"
android:fromDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:startOffset="0"
android:toDegrees="718" />
此后,您可以将rotate.xml
插入进度条,以便PNG文件能够旋转并且只需要保持可见性即可
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_margin="16dp"
android:alpha="0.5"
android:indeterminateDrawable="@drawable/rotate"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
答案 2 :(得分:0)
我建议利用this variant。说实话,你的旋转器并没有那么酷,使它成为1比1。
如果找不到正常的解决方案。你可以制作你的观点。
class DrawThread extends Thread{
private boolean runFlag = false;
private SurfaceHolder surfaceHolder;
private Bitmap picture;
private Matrix matrix;
private long prevTime;
public DrawThread(SurfaceHolder surfaceHolder, Resources resources){
this.surfaceHolder = surfaceHolder;
picture = BitmapFactory.decodeResource(resources, R.drawable.spinner);
matrix = new Matrix();
matrix.postScale(3.0f, 3.0f);
matrix.postTranslate(100.0f, 100.0f);
prevTime = System.currentTimeMillis();
}
public void setRunning(boolean run) {
runFlag = run;
}
@Override
public void run() {
Canvas canvas;
while (runFlag) {
long now = System.currentTimeMillis();
long elapsedTime = now - prevTime;
if (elapsedTime > 30){
prevTime = now;
matrix.preRotate(2.0f, picture.getWidth() / 2, picture.getHeight() / 2);
}
canvas = null;
try {
canvas = surfaceHolder.lockCanvas(null);
synchronized (surfaceHolder) {
canvas.drawColor(Color.BLACK);
canvas.drawBitmap(picture, matrix, null);
}
}
finally {
if (canvas != null) {
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
}
public class MySurfaceView extends SurfaceView implements SurfaceHolder.Callback {
private DrawThread drawThread;
public MySurfaceView(Context context) {
super(context);
getHolder().addCallback(this);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
drawThread = new DrawThread(getHolder(), getResources());
drawThread.setRunning(true);
drawThread.start();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
drawThread.setRunning(false);
while (retry) {
try {
drawThread.join();
retry = false;
} catch (InterruptedException e) {
}
}
}
}