所以我得到这个 W/StaticLayout: maxLineHeight 不应该是-1。maxLines:1 lineCount:1 向日志发送垃圾邮件,我在这里阅读的答案表明它是一个已修复但仍然存在的错误,但想知道是否有人有解决方法,发布问题的用户发现这是一个问题使用最大线和椭圆大小,但我没有使用,如果有人可以帮助我会很感激,我在视图寻呼机中有一个视图寻呼机,它显示带有底部导航视图和一些选项卡的卡片(请不要质疑设计在这种疯狂中有一种方法)这是我的内部视图寻呼机布局
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:attrs="http://schemas.android.com/tools"
android:id="@+id/slide_background"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/title_guideline"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.16" />
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/ThemeOverlay.MyTitleText"
android:text="@string/choose_a_theme"
android:textColor="@color/background_light"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/title_guideline"
android:gravity="center"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/content"
android:layout_width="match_parent"
app:layout_constraintTop_toBottomOf="@id/title_guideline"
app:layout_constraintBottom_toTopOf="@id/spacer"
android:layout_height="0dp">
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/pageIndicatorView"/>
<com.rd.PageIndicatorView
android:id="@+id/pageIndicatorView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/view_pager"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="@id/sub_title_guideline"
android:layout_marginTop="16dp"
app:piv_animationType="slide"
app:piv_dynamicCount="true"
app:piv_interactiveAnimation="true"
app:piv_selectedColor="@android:color/white"
app:piv_unselectedColor="@color/accent_yellow"
app:piv_viewPager="@id/view_pager"
attrs:piv_padding="12dp"
attrs:piv_radius="8dp"/>
<androidx.constraintlayout.widget.Guideline
android:id="@+id/sub_title_guideline"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.84" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/ThemeOverlay.MyBodyText"
app:layout_constraintTop_toBottomOf="@id/sub_title_guideline"
app:layout_constraintBottom_toBottomOf="parent"
android:gravity="center"
android:paddingTop="@dimen/activity_horizontal_margin_4dp"
android:paddingBottom="@dimen/activity_horizontal_margin_4dp"
android:paddingStart="@dimen/activity_horizontal_margin_32dp"
android:paddingEnd="@dimen/activity_horizontal_margin_32dp"
android:id="@+id/subTitle"
android:textColor="@color/background_light"
android:text="@string/please_choose_a_theme"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<View
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/spacer"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
这是我的视图持有者,它包含一个工具栏、选项卡和底部导航栏,整个东西本质上是一个虚拟布局,让用户预览给定特定主题的布局看起来像什么,我的任何一个都没有除了设置颜色之外的样式,
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintWidth_percent="0.8"
app:layout_constraintWidth_max="@dimen/max_create_profile_card"
app:cardElevation="@dimen/activity_horizontal_margin_8dp"
app:cardCornerRadius="8dp"
android:layout_margin="@dimen/activity_horizontal_margin_4dp"
app:cardBackgroundColor="@color/background_light">
<androidx.appcompat.widget.Toolbar
style="?attr/toolbarStyle"
android:layout_width="match_parent"
android:layout_height="56dp"
android:id="@+id/preview_toolbar"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:id="@+id/sentence_container"
app:layout_constraintTop_toTopOf="parent"/>
<com.google.android.material.tabs.TabLayout
style="?attr/tabLayoutStyle"
android:layout_width="match_parent"
android:layout_height="56dp"
android:id="@+id/preview_tabs"
app:layout_constraintTop_toBottomOf="@id/sentence_container">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</com.google.android.material.tabs.TabLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:id="@+id/space"
app:layout_constraintTop_toBottomOf="@id/preview_tabs"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background_light"
style="@style/Widget.MaterialComponents.BottomNavigationView.Colored"
app:layout_constraintTop_toBottomOf="@id/space"
app:menu="@menu/navigation" />
<com.github.sealstudios.fab.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/speak_fab"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/preview_tabs"
android:src="@drawable/ic_play_arrow_white_24dp"
app:fab_size="mini"
android:layout_margin="@dimen/fab_margin"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
我将这些属性设置为我的 tablayout
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
tabLayout.setTabMode(TabLayout.MODE_FIXED);
我像这样设置标签图标和文本
private void setUpMaterialTabs(String[] labels,int[] tabIcons){
for (int i = 0; i < labels.length; i++){
int index = i * 2;
Tab tab = tabLayout.getTabAt(i);
if (theme.equals(Constants.THEME_YELLOW)){
Objects.requireNonNull(tab).setIcon(tabIcons[index]);
}else{
Objects.requireNonNull(tab).setIcon(tabIcons[index + 1]);
}
tab.setText(labels[i]);
}
setTabTextColor(theme, getActivity());
}