使用循环进度创建汽车车速表

时间:2018-04-03 03:46:35

标签: java android android-studio progress-bar android-location

enter image description here我有一个循环进度条,我想要用它来测量速度,就像汽车车速表,但我不知道如何做到这一点SOMETHING LIKE THIS。或者如果可以使用循环进度条。所以我正在做的是将速度存储在一个变量中,并使用progressbar.setProgress来获得速度。但它没有用,因为我觉得不对,所以欢迎任何建议或建议。

MainActivity:

public class MainActivity extends AppCompatActivity {
 ProgressBar mprogressBar;

 @Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mprogressBar = (ProgressBar) findViewById(R.id.circular_progress_bar);
    ObjectAnimator anim = ObjectAnimator.ofInt(mprogressBar, "progress", (int)speeeeed, 25);
    Log.e("valor de speed", Double.toString(speeeeed));
    mprogressBar.setProgress((int) speeeeed);
    anim.setDuration(15000);
    anim.setInterpolator(new DecelerateInterpolator());
    anim.start();
}



LocationListener locationListener = new LocationListener() {
        public void onLocationChanged(Location location) {

                float Real =(location.getSpeed()*3600/1000);
                String convertedSpeed = String.format("%.2f",Real);
                TVKm.setText(convertedSpeed);
    }

        public void onStatusChanged(String provider, int status,
                                    Bundle extras) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onProviderDisabled(String provider) {
        }
    };

circularprogressbar.xml

<shape
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:innerRadiusRatio="2.3"
  android:shape="ring"
  android:thickness="10dp"
  android:useLevel="true">
<solid android:color="#e6c009" />

activity_main.xml中

 <ProgressBar
            android:id="@+id/circular_progress_bar"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_marginTop="30dp"
            android:indeterminate="false"
            android:max="48"
            android:progress="1"
            android:progressDrawable="@drawable/circular_progressbar" />

0 个答案:

没有答案