自定義View之刻度尺---RulerView

自定義View之刻度尺

運(yùn)行截圖

rulerview.png

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

dependencies {
    compile 'com.github.shichunlei:RulerView:1.0.0'
}

或者

Step 1. Add the JitPack repository to your build file

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Step 2. Add the dependency

<dependency>
    <groupId>com.github.shichunlei</groupId>
    <artifactId>RulerView</artifactId>
    <version>1.0.0</version>
</dependency>

用法

1、xml

<com.chingtech.rulerview.library.RulerView
    android:id="@+id/ruler"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    app:rv_alphaEnable="true"
    app:rv_indcatorColor="#414"
    app:rv_indcatorType="triangle"
    app:rv_indcatorWidth="5dp"
    app:rv_itemSpacing="8dp"
    app:rv_maxLineColor="@color/colorPrimary"
    app:rv_maxLineHeight="30dp"
    app:rv_maxLineWidth="3dp"
    app:rv_middleLineColor="#ee2"
    app:rv_middleLineHeight="20dp"
    app:rv_middleLineWidth="2dp"
    app:rv_minLineColor="#e6f"
    app:rv_minLineHeight="10dp"
    app:rv_minLineWidth="1dp"
    app:rv_resultTextColor="#444"
    app:rv_resultTextSize="20sp"
    app:rv_scaleTextColor="#e42"
    app:rv_scaleTextSize="15sp"
    app:rv_unit="CM"
    app:rv_unitTextColor="#666"
    app:rv_unitTextSize="15sp" />

2、java

RulerView rulerview = findViewById(R.id.ruler);

rulerview.initViewParam(78, 20, 180f, 1f);
rulerview.setChooseValueChangeListener(new RulerView.OnChooseResulterListener() {
    @Override
    public void onChooseValueChange(float value) {
        // TODO do some work
    }
});

自定義屬性

<declare-styleable name="RulerView">
    <attr format="float|reference" name="rv_defaultValue" />              <!-- 默認(rèn)值 -->
    <attr format="float|reference" name="rv_minValue" />                  <!-- 最小值 -->
    <attr format="float|reference" name="rv_maxValue" />                  <!-- 最大值 -->
    <attr format="float|reference" name="rv_spanValue" />                 <!-- 精度,最小支持 0.1 -->
    <attr format="dimension|reference" name="rv_itemSpacing" />           <!-- 每個(gè)刻度間的寬度 -->
    <attr format="dimension|reference" name="rv_minLineHeight" />         <!-- 最短刻度線長(zhǎng)度 -->
    <attr format="dimension|reference" name="rv_maxLineHeight" />         <!-- 最長(zhǎng)刻度線長(zhǎng)度 -->
    <attr format="dimension|reference" name="rv_middleLineHeight" />      <!-- 中間刻度線長(zhǎng)度 -->
    <attr format="dimension|reference" name="rv_minLineWidth" />          <!-- 最短刻度線寬度 -->
    <attr format="dimension|reference" name="rv_maxLineWidth" />          <!-- 最長(zhǎng)刻度線寬度 -->
    <attr format="dimension|reference" name="rv_middleLineWidth" />       <!-- 中間刻度線寬度 -->
    <attr format="color|reference" name="rv_scaleTextColor" />            <!-- 刻度盤(pán)文字顏色 -->
    <attr format="color|reference" name="rv_minLineColor" />              <!-- 最短刻度線顏色 -->
    <attr format="color|reference" name="rv_maxLineColor" />              <!-- 最大刻度線顏色 -->
    <attr format="color|reference" name="rv_middleLineColor" />           <!-- 中間刻度線顏色 -->
    <attr format="dimension|reference" name="rv_scaleTextSize" />         <!-- 刻度盤(pán)文字大小 -->
    <attr format="dimension|reference" name="rv_textMarginTop" />         <!-- 刻度盤(pán)文字距離刻度邊緣距離 -->
    <attr format="color|reference" name="rv_indcatorColor" />             <!-- 指示器顏色 -->
    <attr format="dimension|reference" name="rv_indcatorWidth" />         <!-- 指示器寬度,形狀為三角時(shí)不起作用 -->
    <attr format="dimension|reference" name="rv_indcatorHeight" />        <!-- 指示器高度,形狀為三角時(shí)不起作用 -->
    <attr format="enum|reference" name="rv_indcatorType">                 <!-- 指示器形狀 -->
        <enum name="line" value="1" />                                    <!-- 線 -->
        <enum name="triangle" value="2" />                                <!-- 三角 -->
    </attr>
    <attr format="enum|reference" name="rv_strokeCap">                    <!-- 刻度線線帽 -->
        <enum name="round" value="1" />                                   <!-- 圓角 -->
        <enum name="butt" value="0" />                                    <!-- 無(wú)圓角 -->
        <enum name="square" value="2" />                                  <!-- 矩形 -->
    </attr>
    <attr format="color|reference" name="rv_resultTextColor" />           <!-- 結(jié)果文字顏色 -->
    <attr format="color|reference" name="rv_unitTextColor" />             <!-- 單位文字顏色 -->
    <attr format="dimension|reference" name="rv_resultTextSize" />        <!-- 結(jié)果文字大小 -->
    <attr format="dimension|reference" name="rv_unitTextSize" />          <!-- 單位文字大小 -->
    <attr format="string|reference" name="rv_unit" />                     <!-- 單位 -->
    <attr format="boolean|reference" name="rv_showResult" />              <!-- 是否顯示結(jié)果 -->
    <attr format="boolean|reference" name="rv_showUnit" />                <!-- 是否顯示單位 -->
    <attr format="boolean|reference" name="rv_alphaEnable" />             <!-- 是否刻度漸變 -->
</declare-styleable>

源碼地址:https://github.com/shichunlei/RulerView

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開(kāi)發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見(jiàn)模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,506評(píng)論 19 139
  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,640評(píng)論 5 6
  • afinalAfinal是一個(gè)android的ioc,orm框架 https://github.com/yangf...
    passiontim閱讀 15,837評(píng)論 2 45
  • 史蒂芬說(shuō),為了獲得公眾成功,從獨(dú)立期,走向互賴期,我們需要做出一個(gè)重要的改變,或者說(shuō)養(yǎng)成一個(gè)重要的習(xí)慣:知彼解己(...
    謝有為閱讀 846評(píng)論 0 1
  • 今天下午,我去參加它radio的朗讀會(huì),關(guān)于出現(xiàn)在我們生命中的小動(dòng)物的朗讀會(huì)。 朗讀會(huì)在中國(guó)外文書(shū)店進(jìn)行,一個(gè)小小...
    bingo_wonder閱讀 284評(píng)論 0 0

友情鏈接更多精彩內(nèi)容