Android 仿微信/支付寶 字體大小 調(diào)整控件

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)您。

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

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

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