Android TabLayout高度不随字体大小增加而增加
以下是我的Android TabLayout高度不随字体大小增加而增加,android,android-tablayout,Android,Android Tablayout,以下是我的TabLayout <android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorPrimary" app:tabIndicatorHeight="0dp" a
TabLayout
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:tabIndicatorHeight="0dp"
app:tabSelectedTextColor="@android:color/white"
app:tabTextColor="@color/city_grey"
app:tabTextAppearance="@style/DashboardTabLayoutTextAppearance"
android:paddingTop="@dimen/dp10"
android:paddingBottom="@dimen/dp10"
app:tabPaddingStart="@dimen/dp20"
app:tabPaddingEnd="@dimen/dp20"
app:tabMode="scrollable"
app:tabGravity="fill"/>
整数高度=50
让它像……一样充满活力。。。。
tabHost.getTabWidget().getChildAt(i).getLayoutParams().height=(int)(height*this.getResources().getDisplayMetrics().density) 您需要提供动态高度,因为TableLayout有自己的维度,比如工具栏,请尝试使用dimen xml或编程方式。希望它能起作用!!!将“固定高度”设置为“表格布局”可能会解决您的问题同意以编程方式将高度设置为整个屏幕高度的某个百分比,但我如何才能知道需要根据
fontSize
设置的高度?因为在每个屏幕上都会有所不同。如果使用wrap_内容,则会自动进行处理。发布xml文件以了解更多信息。此外,如何设置文本视图也很重要。首先,我使用的是TabLayout
而不是TabHost
,其次,我不能确定50是所有场景中的理想高度。
<style name="DashboardTabLayoutTextAppearance" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textSize">@dimen/sp40</item>
<item name="android:fontFamily">sans-serif-light</item>
</style>
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getChildFragmentManager());
adapter.addFragment(DashboardWeeklyFragment.newInstance(weeklyData), "Weekly");
adapter.addFragment(DashboardMonthlyFragment.newInstance(monthlyData), "Monthly");
adapter.addFragment(DashboardDailyFragment.newInstance(dailyData), "Daily");
viewPager.setAdapter(adapter);
}