使用圆形进度条,例如SPEEDOMETER

时间:2018-06-25 03:49:35

标签: java android android-gps

我有一个圆形的进度条,我希望进度条根据使用GPS的人的速度加载,我的意思是我希望进度条像在汽车上一样做“速度计”。我该如何实现? 我附上一张图片以更好地说明自己。

image

这是加载圆形进度条的代码。

MainActivity.java

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", 0, 100);
    anim.setDuration(15000);
    anim.setInterpolator(new DecelerateInterpolator());
    anim.start();

  }
}

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" />
</shape>

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/circu" />

速度码:

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

        if(mPrevLocation != null){
            mDistanceTravelled += mPrevLocation.distanceTo(location)/100;
            TVDistancia.setText(String.valueOf(mDistanceTravelled));
            Log.e("ROJO",String.valueOf(mDistanceTravelled));
        }
        mPrevLocation = location;

      //  Location oldLoc=0, newLoc=0;
        location.getLatitude();
        location.getLongitude();

        //if(location.hasSpeed()){
            float Real =(location.getSpeed()*3600/1000);
            String convertedSpeed = String.format("%.2f",Real);
            TVKm.setText(convertedSpeed);
            Log.e("Kilometraje",convertedSpeed);

0 个答案:

没有答案