【问题标题】:How to a create custom view with loading animation - filling custom text from left to right?如何使用加载动画创建自定义视图 - 从左到右填充自定义文本?
【发布时间】:2018-03-11 18:21:48
【问题描述】:

我用xml创建加载动画并在activity中播放。

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>

activity中的方法: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里面写什么,才能得到这个

???

【问题讨论】:

    标签: java android android-custom-view android-progressbar


    【解决方案1】:

    我会使用透明文本,下方有一个填充矩形。以下是我的做法:

    我不会使用自定义视图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多