【问题标题】:What is the default height on Androids TabLayoutAndroid TabLayout 的默认高度是多少
【发布时间】:2016-02-13 17:17:41
【问题描述】:

看起来应该很容易找到,但比我想象的要难。 DIP 中 TabLayout 的默认高度是多少?

【问题讨论】:

  • 如何将其设置为默认高度,我讨厌根据不同的屏幕分辨率添加很多自定义高度
  • @ShirishHerwade 如果您在 xml 中将高度设置为 wrap_content,那么它将自动调整为默认高度。如果要显式设置高度,则在 xml 中将高度设置为 48dp。根据屏幕分辨率使用 dp 大小。如果您尝试动态设置高度,那么您必须将高度乘以基于屏幕分辨率的浮点数。您可以使用以下行获取屏幕分辨率:getApplication.getResources().getDisplayMetrics().density;
  • 感谢 wrap_content 工作

标签: android layout tabs height


【解决方案1】:

Material Design guidelines 声明当你有文本或图像时这个高度等于 48dp,当你有图像和文本时这个高度等于 72dp。

【讨论】:

    【解决方案2】:

    它的高度是"?attr/tabIndicatorHeight"

    例如 您可以在 xml 文件中将此值用于另一个视图,例如:

    android:layout_marginBottom="?attr/tabIndicatorHeight"
    

    它在所有设备上看起来都不错。

    【讨论】:

    • 这被标记为已弃用:Instead, set the intrinsic size of the custom drawable provided to the tabIndicator attribute in order to change the indicator height. For example, this can be done by setting the <size> property in a <shape> resource.
    猜你喜欢
    • 2010-10-10
    • 2019-09-22
    • 2015-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多