ProgressBar没有显示出来

时间:2018-01-24 16:22:21

标签: android

编辑:我意识到下面发布的代码在Nexus 6(shamu)和Galaxy Tab A中完美运行,两者都带有android 7.0!并且它没有在Moto G5 Plus(Android 7.0)上显示。

这是一个简单的问题。我的ProgressBar不会出现。我正在尝试直接登录LoginActivity,但我没有成功。我试过的事情:

  1. 将ProgressBar直接放在布局
  2. 将ProgressBar放入布局
  3. 设置ProgressBar propriety indeterminate为true
  4. 将进度条和父级布局的可见性设置为VISIBLE
  5. 创建一个单独的.xml文件并调用一个Dialog(在这种情况下,如果我在文本中放置textview会出现但是进度条不会出现)
  6. 更改礼节layout_width和layout_height
  7. 上述所有步骤的组合
  8. 最后我尝试创建这个简单的空白活动,只显示进度条......
  9. activity_test.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="context_name_here">
    
        <LinearLayout
            android:layout_width="368dp"
            android:layout_height="495dp"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:orientation="vertical"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">
    
            <ProgressBar
                android:id="@+id/progressBar2"
                style="?android:attr/progressBarStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:indeterminate="true"
                android:visibility="visible" />
        </LinearLayout>
    </android.support.constraint.ConstraintLayout>
    

    test.java:

    package package_name_here;
    
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    
    public class test extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_test);
        }
    }
    

    有什么问题?我怀疑这是关于资源...默认进度条或Android版本的图像...... 有任何想法吗? 感谢

4 个答案:

答案 0 :(得分:2)

我弄清楚问题是什么。 Animator持续时间刻度必须在设备的Developer选项中为ON: 开发者选项 - &gt;开发者持续时间范围 - &gt; 1x(ON)

答案 1 :(得分:0)

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private ProgressBar progressBar;
    private int progressStatus = 0;
    private TextView textView;
    private Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        progressBar = (ProgressBar) findViewById(R.id.progressBar);
        textView = (TextView) findViewById(R.id.textView);
        // Start long running operation in a background thread
        new Thread(new Runnable() {
            public void run() {
                while (progressStatus < 100) {
                    progressStatus += 1;
                    // Update the progress bar and display the
                    //current value in the text view
                    handler.post(new Runnable() {
                        public void run() {
                            progressBar.setProgress(progressStatus);
                            textView.setText(progressStatus+"/"+progressBar.getMax());
                        }
                    });
                    try {
                        // Sleep for 200 milliseconds.
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }
}

定义XML:

<ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="23dp"
        android:layout_marginTop="20dp"
        android:indeterminate="false"
        android:max="100"
        android:minHeight="50dp"
        android:minWidth="200dp"
        android:progress="1" />

    <ProgressBar
        android:id="@+id/progressBar_cyclic"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:minHeight="50dp"
        android:minWidth="50dp"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

答案 2 :(得分:0)

首先,您需要声明进度对话框

private ProgressBar progressBar;

然后在onCreate

 progressBar = (ProgressBar) findViewById(R.id.progressBar);

    progressBar= new ProgressBar(test.this);

progressBar.show();

要关闭对话框或取消它,您可以使用

progressBar.cancel();progressBar.dismiss();

答案 3 :(得分:0)

尝试对ProgressBar的宽度和高度进行硬编码维度,同时检查可能与活动默认值相同的颜色,也可以通过删除样式属性检查一次,或者尝试使用不同的ProgressBar样式。