Simple gauge view like speedmeter in android?

后端 未结 7 1050
被撕碎了的回忆
被撕碎了的回忆 2020-12-07 16:52

I want to have a simple gauge view where i will define the start value and the end value and have a pointer to show given variable value.

7条回答
  •  臣服心动
    2020-12-07 17:30

    All other gauges you recommended have bugs and don't run fine on Kitkat and Lollipop. Also there is no Android Studio and gradle friendly library here.

    Here's git repo for the more recent one updated for Lollipop you can use with Gradle:

    • https://github.com/Sulejman/GaugeView

    enter image description here

    After you include library in your project add gaugelibrary to xml layout of your activity:

    
    

    This will show static gauge without needle. To instantiate needle with random animation you need to do that in activity class file. See how it's done here:

    package io.sule.testapplication;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.os.CountDownTimer;
    import android.view.Menu;
    import android.view.MenuItem;
    
    import java.util.Random;
    
    import io.sule.gaugelibrary.GaugeView;
    
    public class MainActivity extends Activity {
       private GaugeView mGaugeView;
       private final Random RAND = new Random();
    
       @Override
       protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
    
          mGaugeView = (GaugeView) findViewById(R.id.gauge_view);
          mTimer.start();
       }
    
    
       private final CountDownTimer mTimer = new CountDownTimer(30000, 1000) {
    
          @Override
          public void onTick(final long millisUntilFinished) {
             mGaugeView.setTargetValue(RAND.nextInt(101));
          }
    
          @Override
          public void onFinish() {}
       };
    }
    

    This will instantiate needle and make it animate moving to random values.

提交回复
热议问题