Android : 我想用飞行图像创建装载机

Android : I want to create loader with flight image

我想在 android 中创建与附加 gif 相同的加载器

提前致谢

你的图片中没有平面我更喜欢使用 ProgressBar

但我会更容易使用 SeekBar 作为进度条

所以让我们用最简单的方式

在布局中 XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:hardwareAccelerated="false"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <SeekBar
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:background="#32aaef"
        android:id="@+id/sbHeight"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:max="100"
        android:progress="0"
        android:progressDrawable="@drawable/seekbar_as_progress"
        android:thumb="@drawable/plane"
        />
</LinearLayout>

其中 seekbar_as_progress

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Define the background properties like color etc -->

    <item android:id="@android:id/background">
        <shape

            android:shape="line"
            android:useLevel="true">
            <stroke
                android:width="3dp"
                android:color="#c9c9c9"
                android:dashGap="20dp"
                android:dashWidth="3dp" />
        </shape>
    </item>

    <!-- Define the progress properties like start color, end color etc -->
    <item android:id="@android:id/progress">
        <clip>
            <shape

                android:shape="line"
                android:useLevel="true">
            <stroke
                android:width="6dp"
                android:color="#ffffff"
                android:dashGap="20dp"
                android:dashWidth="4dp" />
            </shape>
        </clip>
    </item>
</layer-list>

@drawable/plane是平面图标

在你的 Activity

  @Override
  protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
    //        DountChart view = new DountChart(this);
            setContentView(R.layout.empty);

            final SeekBar sbHeight = findViewById(R.id.sbHeight);
            sbHeight.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
            sbHeight.setOnTouchListener(new View.OnTouchListener(){
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return true;
                }
            });

            final int[] progress = {0};

            final Handler ha=new Handler();
            ha.postDelayed(new Runnable() {

                @Override
                public void run() {
                    //call function

                    if (progress[0] != 100){
                        AppLogger.log("Prog",progress[0]+"");
                        progress[0]= progress[0]+1;
                        sbHeight.setProgress(progress[0]);
                    ha.postDelayed(this, 100);
                    }
                }
            }, 100);

        }

and that`s All