Reputation: 57
I created loading animation with xml and played it in activity.
xml-file: 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>
method in activity: playAnimation
private void playAnimation() {
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView.setBackgroundResource(R.drawable.anim);
AnimationDrawable animation = (AnimationDrawable) imageView.getBackground();
animation.start();
}
Got:
Need create the same, but need use another way - custom view without drawable resources. Only programmatically drawing.
Something like this:
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) {}
}
What need to write inside CustomLoadingView, to get this
???
Upvotes: 2
Views: 344
Reputation: 469
I would use transparent text with a filling rectangle underneath it. Here's how I would do it:
I wouldn't use a custom view.
Upvotes: 2