android loading框架
时间: 2023-10-02 10:08:53 浏览: 70
在 Android 中实现 Loading 框架有很多种方式,下面列举几种常见的:
1. ProgressDialog:Android 系统自带的进度条对话框,可以直接使用,简单方便。
```java
ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.setMessage("Loading...");
progressDialog.show();
```
2. ProgressBar:可以在布局文件中添加 ProgressBar 控件,然后通过设置可见性来控制显示和隐藏。
```xml
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
```
```java
ProgressBar progressBar = findViewById(R.id.progressBar);
progressBar.setVisibility(View.VISIBLE);
```
3. 自定义 LoadingView:可以自己实现一个自定义控件,来展示自己想要的 Loading 效果。
```java
public class LoadingView extends View {
private Paint paint = new Paint();
private int radius = 20;
public LoadingView(Context context) {
super(context);
paint.setColor(Color.RED);
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.FILL);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius, paint);
}
public void start() {
ValueAnimator animator = ValueAnimator.ofInt(20, 60, 20);
animator.setDuration(1000);
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
radius = (int) animation.getAnimatedValue();
invalidate();
}
});
animator.start();
}
}
```
```java
LoadingView loadingView = new LoadingView(context);
loadingView.start();
```
以上仅是一些简单的示例,实际项目中需要根据具体需求来选择合适的 Loading 框架。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)