簡體   English   中英

如何使用加載動畫創建自定義視圖 - 從左到右填充自定義文本?

[英]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();
}

得到了:

在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里面寫什么,才能得到這個

在android上從左到右填充自定義文本

???

我會使用透明文本,下面有一個填充矩形。 這是我將如何做到的:

我不會使用自定義視圖。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM