您的位置:首页 > 产品设计 > UI/UE

如何在安卓中写用UI美化实现的进度条

2017-06-20 11:15 113 查看
如何使用UI美化写进度条

具体实现的代码如下:

我们的Java文件:

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.wls.tiaotiaotang.TiaoProgress;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

private TiaoProgress tiaoProgress;
private int pro;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tiaoProgress= (TiaoProgress) this.findViewById(R.id.sss);
tiaoProgress.setCircleColor(Color.GREEN);
tiaoProgress.setArrowColor(Color.RED);
tiaoProgress.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (!tiaoProgress.isDownloading()) {
pro=0;
tiaoProgress.startDownload();
handler.sendMessageDelayed(Message.obtain(),200);
}
}
@SuppressLint("HandlerLeak")
private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
if (pro<100)
{
pro+=1;
tiaoProgress.setProgress(pro);
handler.sendMessageDelayed(Message.obtain(),100);
}
super.handleMessage(msg);
}
};
}


我们的XML文件:





<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="com.example.xue.ui.MainActivity">

<com.wls.tiaotiaotang.TiaoProgress
android:id="@+id/sss"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>


[b]最后我们一定不要忘记加依赖:[/b]





allprojects {
repositories {
jcenter()
maven { url 'https://jitpack.io'}//这是写进度条加的依赖
}
}


dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'

testCompile 'junit:junit:4.12'

compile 'com.github.wlsj:TiaoTiao:V1.0'//这是写进度条加的依赖

}


以上就可以实现经过UI美化后的进度条.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: