如何解决TabLayout - 带图标的多行标签标题
在选项卡上,我需要一个图标和一个单行或两行文本,具体取决于其长度。只要我没有图标,一切都会按预期工作。适合一行的标题显示在一行中,不占一行的标题显示在一行中。当我添加一个图标时,文本开始被强制排成一行(更不用说它被剪裁在左侧)。见下图对比:
我可以在不创建自定义标签布局的情况下实现图标存在时的多行文字效果吗?
我的代码:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabInlineLabel="true"
app:tabMaxWidth="150dp"
app:tabMode="scrollable"/>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
TabLayoutMediator(binding.tabLayout,binding.viewPager) { tab,position ->
tab.text = "Long text which takes multiple lines"
tab.icon = ContextCompat.getDrawable(requireContext(),R.drawable.ic_add)
}.attach()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。