Android 仪表板 DashboardView

DashboardView

Sample 下载
Github 项目地址好用的话请给个 star 支持一下

这是一个Android仪表板View,就像汽车等机械仪表板一样。 支持许多自定义样式。

预览图


使用

Gradle ​

修改项目 build.gradle,增加下面代码:

    dependencies {
        compile 'com.ayst.dbv:dashboardview:1.5.1'
    }

Java

    public class MainActivity extends AppCompatActivity {
    
        private DashboardView mDashboardView;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            mDashboardView = (DashboardView) findViewById(R.id.dashboardview_1);
            mDashboardView.setValue(50); // Set value
            mDashboardView.resetValue(50); // Set value and clear maximum and minimum
        }
    }

XML

如果决定使用DashboardView作为视图,则可以在xml布局中定义它,如下所示:

   <com.ayst.dashboardview.DashboardView
       android:id="@+id/dashboardview_1"
       android:layout_width="300dp"
       android:layout_height="wrap_content"
       app:dbv_firstColor="@color/red"
       app:dbv_secondColor="@color/yellow"
       app:dbv_thirdColor="@color/green"
       app:dbv_max="0"
       app:dbv_min="-100"
       app:dbv_section="10"
       app:dbv_portion="10"
       app:dbv_lineWidth="2dp"
       app:dbv_colorWidth="10dp"
       app:dbv_colorPadding="10dp"
       app:dbv_longScaleLength="15dp"
       app:dbv_shortScaleLength="10dp"
       app:dbv_startAngle="180"
       app:dbv_sweepAngle="180"
       app:dbv_value="-30"
       app:dbv_showValueText="false"
       app:dbv_showPointerRange="true"
       app:dbv_firstRange="30"
       app:dbv_secondRange="20"
       app:dbv_headerText="dbm"
       app:dbv_headerTextColor="@color/white"
       app:dbv_pointerColor="@color/white"
       app:dbv_minPointerColor="@color/white_30"
       app:dbv_maxPointerColor="@color/white_30"
       app:dbv_scaleColor="@color/white"
       app:dbv_scaleTextSize="12sp"
       />

NOTE:

  • dbv_firstColor - First range color
  • dbv_secondColor - Second range color
  • dbv_thirdColor - Third range color
  • dbv_max - Max value
  • dbv_min - Min value
  • dbv_section - Value range (mMax-mMin) equal parts
  • dbv_portion - One section equal parts
  • dbv_lineWidth - Line stroke width
  • dbv_colorWidth - Color progress stroke width
  • dbv_colorPadding - Color progress padding
  • dbv_longScaleLength - Length of long scale
  • dbv_shortScaleLength - Length of short scale
  • dbv_startAngle - Starting angle, 0 degrees at 3 o'clock
  • dbv_sweepAngle - Draw the angle, the difference from the start angle to the end
  • dbv_value - Value
  • dbv_showValueText - Whether to display value text
  • dbv_showPointerRange - Whether to display pointer range
  • dbv_firstRange - This is a percentage, starting with the minimum value, showing first color within this percentage
  • dbv_secondRange - This is a percentage, starting with the first range, showing second color within this percentage
  • dbv_headerText - The header text
  • dbv_headerTextColor - Header text color
  • dbv_pointerColor - Pointer color
  • dbv_minPointerColor - Min Pointer color
  • dbv_maxPointerColor - Max Pointer color
  • dbv_scaleColor - Scale color
  • dbv_scaleTextSize - Scale text size
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。