FontResize
FontResize是一個仿微信/支付寶 字體大小 調(diào)整控件的庫
gradle依賴
implementation 'com.ljx.view:fontresize:1.0.1'
該庫里面只有一個類FontResizeView,故不用擔(dān)心庫很大。

image
屬性說明
<declare-styleable name="FontResizeView">
<attr name="minSize" format="reference|dimension" /> <!--最小size-->
<attr name="maxSize" format="reference|dimension" /> <!--最大size-->
<attr name="totalGrade" format="integer" /> <!--可調(diào)整的等級、即總的等級-->
<attr name="standardGrade" format="integer" /> <!--標(biāo)準(zhǔn)等級-->
<attr name="leftText" format="reference|string" /> <!--左邊文本,默認(rèn)為 'A'-->
<attr name="middleText" format="reference|string" /> <!--中間文本,默認(rèn)為 '標(biāo)準(zhǔn)'-->
<attr name="rightText" format="reference|string" /> <!--右邊文本,默認(rèn)為 'A'-->
<attr name="leftTextColor" format="reference|color" /> <!--左邊文本顏色,默認(rèn)為全黑-->
<attr name="middleTextColor" format="reference|color" /> <!--中間文本顏色,默認(rèn)為全黑-->
<attr name="rightTextColor" format="reference|color" /> <!--右邊文本顏色,默認(rèn)為全黑-->
<attr name="sliderRadius" format="reference|dimension" /> <!--滑塊半徑-->
<attr name="sliderColor" format="reference|color" /> <!--滑塊顏色-->
<attr name="sliderShadowColor" format="reference|color" /> <!--滑塊邊緣陰影顏色-->
<attr name="lineColor" format="reference|color" /> <!--線條顏色-->
<attr name="lineStrokeWidth" format="reference|dimension" /> <!--線條寬度,即粗細(xì)程度-->
<attr name="horizontalLineLength" format="reference|dimension" /> <!--橫向線條長度-->
<attr name="verticalLineLength" format="reference|dimension" /> <!--縱向線條長度-->
</declare-styleable>
xml配置
<com.ljx.view.FontResizeView
android:id="@+id/font_resize_view"
android:layout_width="match_parent"
android:layout_height="140dp"
android:background="@android:color/white"
app:maxSize="25sp"
app:minSize="13sp"
app:sliderColor="@android:color/white"
app:sliderRadius="12dp"
app:standardGrade="2"
app:totalGrade="7" />
設(shè)置回調(diào)
FontResizeView fontResizeView = findViewById(R.id.font_resize_view);
fontResizeView.setOnFontChangeListener(new OnFontChangeListener() {
@Override
public void onFontChange(float fontSize) {
//字體size改變回調(diào) 單位:sp
}
});
這樣配置過后,代碼跑起來效果就跟上面的 gif 動圖一樣
我們把所有屬性都加上,看看效果
<com.ljx.view.FontResizeView
android:id="@+id/font_resize_view"
android:layout_width="match_parent"
android:layout_height="140dp"
android:background="@android:color/white"
app:horizontalLineLength="300dp"
app:leftText="AA"
app:leftTextColor="#FF0000"
app:lineColor="#009999"
app:lineStrokeWidth="2dp"
app:maxSize="31sp"
app:minSize="15sp"
app:middleText="標(biāo)準(zhǔn)1"
app:middleTextColor="#00FF00"
app:rightText="AAA"
app:rightTextColor="#0000FF"
app:sliderColor="@android:color/white"
app:sliderRadius="13dp"
app:sliderShadowColor="#FF0000"
app:standardGrade="3"
app:totalGrade="9"
app:verticalLineLength="15dp" />
效果如下

image
相信以上屬性已經(jīng)能滿足大部分場景,如果不能滿足您的場景,請?zhí)岢瞿男枨?,我會第一時間回應(yīng)您。