我正在使用android中的ProgressBar类,但是我无法在5秒内完成它并加载应用程序.一切正常但进度条没有进展.这是代码.
public class StartPoint extends Activity{
ProgressBar progressBar;
private int progressBarStatus = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
progressBar = (ProgressBar)findViewById(R.id.progressBar1);
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
while(progressBarStatus < 5000){
progressBar.setProgress(progressBarStatus);
progressBarStatus += 1000;
}
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent openMainList = new Intent(StartPoint.this, in.isuru.caf.MainList.class);
startActivity(openMainList);
}
}
};
timer.start();
}
protected void onPause(){
super.onPause();
finish();
}
}
Run Code Online (Sandbox Code Playgroud)
这是布局文件splash.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > …Run Code Online (Sandbox Code Playgroud) 我想在android中创建一个像该图像一样的进度条

我尝试使用
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/loadingicon"
android:pivotX="50%"
android:pivotY="50%" />
Run Code Online (Sandbox Code Playgroud)
但我认为它不符合我的要求
我有一个按钮,按下后,执行以下代码:
public void onClick(View v) {
// TODO Auto-generated method stub
//progressSpin.setVisibility(View.VISIBLE);
try {
data=new WebkioskExtractor().execute(username,password).get();
System.out.println("Data = "+data);
} catch (Exception e) {
// TODO Auto-geneorated catch block
e.printStackTrace();
}
//progressSpin.setVisibility(View.GONE);
}
Run Code Online (Sandbox Code Playgroud)
从代码中清楚,我必须等待AsyncTask完成,因为我依赖于它返回的数据.问题是,当执行任务(从互联网上获取一些数据)时,按钮仍处于按下状态.即使我将我创建的进度条设置为VISIBLE,也不会显示.
我怎样才能解决这个问题?我希望按下按钮一次,然后进度条应该开始旋转,这不会发生.
我希望这将是一个我想念的傻事,但我一直在敲击键盘试图弄清楚我哪里出错了.
我正在尝试从新线程中的DownloadManager更新ProgressBar.这是正常工作,直到中途,ProgressBar重新开始重新开始.从输入一些调试代码,我已将问题隔离到这一行:
final int dl_progress = (bytes_downloaded*100)/bytes_total;
Run Code Online (Sandbox Code Playgroud)
dl_progress正在通过文件下载中途转为负面!下面的相关代码块和日志输出:
@Override
public void run() {
boolean downloading = true;
while (downloading) {
DownloadManager.Query q = new DownloadManager.Query();
q.setFilterById(downloadId);
Cursor cursor = manager.query(q);
cursor.moveToFirst();
int bytes_downloaded = cursor.getInt(cursor
.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
int bytes_total = cursor.getInt(cursor
.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
if (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_SUCCESSFUL) {
downloading = false;
getActivity().runOnUiThread(new Runnable() {
public void run() {
mProgressBar.setVisibility(View.INVISIBLE);
}
});
}
final int dl_progress = (bytes_downloaded*100)/bytes_total;
Log.d("Download", bytes_downloaded + " of " + bytes_total + " (" + dl_progress + …Run Code Online (Sandbox Code Playgroud) 我有一个WebView,可以很好地加载URL.我已经获得了一个WebViewClient并扩展了onProgressChanged,但据我所知,它没有被调用.有任何想法吗?
wv.setWebViewClient(new WebViewClient(){
public void onProgressChanged(final WebView view, final int newProgress) {
Log.e("APPNAME", String.valueOf(newProgress));
if (newProgress < 100 && progressBar.getVisibility() == ProgressBar.GONE){
progressBar.setVisibility(ProgressBar.VISIBLE);
}
progressBar.setProgress(newProgress);
progressTxt.setText(newProgress);
if (newProgress == 100){
progressBar.setVisibility(ProgressBar.GONE);
}
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
InputStream is = null;
byte[] buffer = null;
try {
is = getAssets().open("error.html");
int size = 0;
size = is.available();
buffer = new byte[size];
is.read(buffer);
is.close();
}
catch(Exception e){
}
String str = new String(buffer);
str = …Run Code Online (Sandbox Code Playgroud) 我已经开发了一个具有一个Web视图和一个进度条的应用程序,所以我想在加载网页的进度条中添加显示进度等功能,以便它如何实现我有我放在这里的代码.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
web = (WebView) findViewById(R.id.web);
progressBar = (ProgressBar) findViewById(R.id.progrss);
web.setWebViewClient(new myWebClient());
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("http://www.technotalkative.com");
}
public class myWebClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
} …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有一个自定义进度条
progress.xml
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:progressDrawable="@drawable/loader" />
Run Code Online (Sandbox Code Playgroud)
我的gif文件

我想用这个图像创建一个进度条
换句话说,我想在每次从服务器下载数据时显示此图像,并在下载数据后将其删除
或者你可以说,如何将此图像显示为进度条
我正在使用WebViewClient加载网页,我想显示我的代码的进度条.我的代码没有逐渐加载进度.它只显示100%的进展.如何根据网页加载时间设置进度?
出于我的目的,我只需在WebView上加载" https://www.google.com ".请帮忙.谢谢.代码如下所示:
活动文件
public class MainActivity extends Activity {
private WebView webView;
private ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int vc = Color.parseColor("#feca01");
progressBar = (ProgressBar) findViewById(R.id.determinateBar);
progressBar.getProgressDrawable().setColorFilter(
vc, android.graphics.PorterDuff.Mode.SRC_IN);
webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new MyBrowser());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://deelay.me/5000/http://www.google.com");
}
private class MyBrowser extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon)
{
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
progressBar.incrementProgressBy(10);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override …Run Code Online (Sandbox Code Playgroud) 我想创建 1 分钟的计时器进度条。我使用了以下代码,但它从 60 到 0 开始,而使用相同的过程,我必须从 0 到 60 开始。
public static void animateTimerProgress(int currentTimeDuration, final int maxTimeDuration, boolean withStartDelay, final DonutProgress timeOutProgressView, Runnable endAction) {
final int duration = currentTimeDuration < 0 ? 1 : currentTimeDuration;
timeOutProgressView.setMax(maxTimeDuration);
timeOutProgressView.setProgress(duration);
timeOutProgressView.animate()
.setDuration(duration * SECOND_IN_MILLIS)
.setInterpolator(new LinearInterpolator())
.setStartDelay(withStartDelay ? TIMEOUT_START_DELAY : 0)
.setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
int progress = 1 + (int) ((1f - valueAnimator.getAnimatedFraction()) * (duration - 1f));
timeOutProgressView.setProgress(progress);
}
})
.withEndAction(endAction)
.start();
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。
这是我的布局 xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/fragment_body"
android:fitsSystemWindows="true">
<include
android:id="@+id/contextToolBar"
layout="@layout/context_toolbar_layout" />
<android.support.v7.widget.RecyclerView
android:id="@+id/list1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/contextToolBar"
android:scrollbarSize="5dp"
android:scrollbarThumbVertical="@color/scrollbarColor"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<ProgressBar
android:id="@+id/delete_progress"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone" />
Run Code Online (Sandbox Code Playgroud)
它在回收视图中显示图像网格。我可以选择一堆图像并可以选择删除它们。以下是删除逻辑:
public void deleteSelectedFiles(final Context context, final List<MediaModel> selectionList) {
String confirmationMessage = getString(R.string.delete_confirm_message);
new AlertDialog.Builder(context)
.setTitle(getString(R.string.action_delete))
.setMessage(confirmationMessage)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, (dialog, whichButton) -> {
View progressBar = getActivity().findViewById(R.id.delete_progress);
dialog.cancel();
progressBar.setVisibility(View.VISIBLE);
deleteFileList(selectionList, this.getActivity());
progressBar.setVisibility(View.GONE);
})
.setNegativeButton(android.R.string.no, null).show();
}
Run Code Online (Sandbox Code Playgroud)
我希望在删除操作进行时进度条显示在前台。但它只是不显示。任何帮助将不胜感激。
android android-layout android-progressbar progress-bar android-recyclerview