代码之家  ›  专栏  ›  技术社区  ›  Andrew Ilchenko

如何通过加载动画创建自定义视图-从左到右填充自定义文本?

  •  2
  • Andrew Ilchenko  · 技术社区  · 8 年前

    我用xml创建了加载动画,并在活动中播放。

    xml文件:动画。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>
    

    活动中的方法:播放动画

    private void playAnimation() {    
        ImageView imageView = (ImageView) findViewById(R.id.imageView);
        imageView.setBackgroundResource(R.drawable.anim);
        AnimationDrawable animation = (AnimationDrawable) imageView.getBackground();
        animation.start();
    }
    

    得到了:

    filling custom text from left to right on android

    类似这样:

    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中需要写什么才能得到这个

    filling custom text from left to right on android

    1 回复  |  直到 8 年前
        1
  •  2
  •   Jans Rautenbach    8 年前

    我会使用透明文本,下面有一个填充矩形。我会这样做:

    我不会使用自定义视图。