[英]How to a create custom view with loading animation - filling custom text from left to right?
我用xml创建了加载动画并在活动中播放。
xml 文件:anim.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/loading_00001" android:duration="50" />
<item android:drawable="@drawable/loading_00002" android:duration="50" />
<item android:drawable="@drawable/loading_00003" android:duration="50" />
<item android:drawable="@drawable/loading_00004" android:duration="50" />
<item android:drawable="@drawable/loading_00005" android:duration="50" />
</animation-list>
活动中的方法:playAnimation
private void playAnimation() {
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setBackgroundResource(R.drawable.anim);
AnimationDrawable animation = (AnimationDrawable) imageView.getBackground();
animation.start();
}
得到了:
需要创建相同的,但需要使用另一种方式 - 没有可绘制资源的自定义视图。 只能以编程方式绘制。
像这样的东西:
public CustomLoadingView extends View {
public CustomLoadingView(Context context) {
this(context, null);
}
public CustomLoadingView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public CustomLoadingView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(attrs);
}
private void init(AttributeSet attrs) {}
@Override
protected void onDraw(Canvas canvas) {}
}
需要在CustomLoadingView里面写什么,才能得到这个
???
我会使用透明文本,下面有一个填充矩形。 这是我将如何做到的:
我不会使用自定义视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.