仿猎豹扫描进度

Posted 小喽啰A

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了仿猎豹扫描进度相关的知识,希望对你有一定的参考价值。

布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/bbb" />

    <ImageView
        android:id="@+id/forg"
        android:layout_width="wrap_content"
        android:layout_height="150dp"
        android:layout_alignTop="@+id/back"
        android:layout_centerHorizontal="true"
        android:scaleType="matrix"
        android:src="@drawable/aaa" />
    
    <ImageView 
        android:id="@+id/saomiao"
        android:layout_below="@+id/forg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ccc"
        android:visibility="visible"
        android:layout_centerHorizontal="true"
        />
    <TextView 
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="20%"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:textSize="25sp"
        android:layout_below="@+id/back"
        />

</RelativeLayout>


逻辑代码

package com.wlong.clean;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;


public class MainActivity extends Activity 

	
	private View forg;
	private View shade;
	private TextView percent;
    @Override
    protected void onCreate(Bundle savedInstanceState) 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        forg = findViewById(R.id.forg);
        shade = findViewById(R.id.saomiao);
        percent = (TextView) findViewById(R.id.text);
        
        startAnim();
    

    
    private void startAnim()
    	new AsyncTask<Void, Integer, Void>()
    		private int h ;
			@Override
			protected Void doInBackground(Void... arg0) 
				
				for (int i = 0; i < 100; i++) 
					SystemClock.sleep(45);
					this.publishProgress(i);
					
				
				
				return null;
			
			
			protected void onPreExecute() 
				h = forg.getLayoutParams().height;
				forg.setVisibility(View.VISIBLE);
				shade.setVisibility(View.VISIBLE);
			;
			
			protected void onProgressUpdate(Integer[] values) 
				int progress = values[0].intValue();
				int height = ((100-progress) * h)/100;
				
				LayoutParams lp = (LayoutParams) forg.getLayoutParams();
				lp.height = height;
				
				forg.setLayoutParams(lp);
				forg.invalidate();
				
				shade.invalidate();
				
				percent.setText(progress + "%");
			;
			
			protected void onPostExecute(Void result) 
				forg.setVisibility(View.GONE);
				shade.setVisibility(View.GONE);
				percent.setText(100 + "%");
			;
    		
    	.execute();
    





以上是关于仿猎豹扫描进度的主要内容,如果未能解决你的问题,请参考以下文章

猎豹MFC--进度条CProgressCtrl 定时器SetTimer

仿苹果AppStore 下载进度条

仿IOS圆形下载进度条

仿今日头条项目新进度

仿字节颜色自定义Android进度条

Android仿IOS ViewPager滑动进度条