- Android-推荐一个自动调整文字大小的开源库(AutoFit
- Android-推荐一个弹窗开源库XPopup
- Android-推荐一个WebView开源库(AgentWeb)
- Android-推荐一个日历开源库(CalendarView)
- Android-推荐一个Toast开源库(ToastUtils
- Android-推荐一个工具开源库(AndroidUtilCod
- Android-推荐一个折叠文本开源库(ExpandableTe
- Android-推荐一个圆形图片开源库(CircleImageV
- Android-推荐一个TextView效果开源库( Super
- Android-推荐一个RecyclerView动画开源库( r

在日常的开发中,我们可能会遇到说根据容器自动调整文字大小的需求。这篇博客分享一个开源库帮大家快速实现,希望能帮看文章的小伙伴提高开发效率。
AutoFitTextView
一个实现自动调整文本大小以完全适应其边界的TextView
的开源库。
引入项目
dependencies {
implementation 'me.grantland:autofittextview:0.2.1'
}
截止我发博客,开源库版本是0.2.1
,使用最新版本请看开源文档
使用示例
1、在代码里面使用:
AutofitHelper.create(textView);
2、XML
的使用:
<me.grantland.widget.AutofitLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"/>
</me.grantland.widget.AutofitLayout>
在代码中或者XML
使用内置的Widget
:
<RootElement
xmlns:autofit="http://schemas.android.com/apk/res-auto"
...
<me.grantland.widget.AutofitTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:maxLines="2"
android:textSize="40sp"
autofit:minTextSize="16sp"/>
最后总结,这个开源库更新时间比较久远,如果使用最新的编译器的话,需要自己clone
代码到项目当中修改使用。
网友评论