【问题标题】:android view default padding or marginsandroid查看默认填充或边距
【发布时间】:2012-07-10 09:12:34
【问题描述】:

似乎一些视图像 TextView 有自己的填充或边距...我的意思是当我将 textSize 16dp 设置为 textView 时,在 hdpi 设备屏幕上需要超过 24 个像素才能显示此控件。也许我错过了什么,请帮助

<LinearLayout
        android:id="@+id/uc_button_title_panel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <View
            android:layout_width="match_parent"
            android:layout_height="1px"
            android:background="@color/closed_red" />

        <TextView
            android:id="@+id/uc_button_title_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:includeFontPadding="false"
            android:background="@null"
            android:padding="0dp"
            android:text="@string/demo_text"
            android:textColor="#325083"
            android:textSize="16dp"
            android:textStyle="bold" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1px"
            android:background="@color/closed_red" />
    </LinearLayout>

【问题讨论】:

  • 您是否期望它正好是 24 基于此处的 1.5 倍乘数:developer.android.com/guide/practices/screens_support.html
  • 好吧..我想如果我想在 hdpi 设备上获得 24px 的文本大小,我必须将 textSize 设置为 16dp 吗?
  • 是的,你是对的,只是想了解这种关系。那么你是说实际文本大于 24px 还是文本 + 周围的空间?
  • 文本和其周围的空间高度为 34 像素
  • 你的布局是什么样的?您的 TextView 很有可能正在填充其父级。或类似的规定。您可能必须发布您的实际布局(无论是在 xml 还是 java 中)。阅读 TextView 源代码,除了与字体相关的填充外,我没有看到任何其他内容。在这篇 SO 帖子中讨论过:stackoverflow.com/questions/4768738/… 您可能还想尝试手动将填充设置为 0,看看是否会改变它...

标签: android view


【解决方案1】:
  <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:layout_marginBottom="@dimen/activity_vertical_margin"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:orientation="vertical">
  </LinearLayout>

在 android 中使用布局时,可用的默认边距和填充是这样的:@dimen/activity_vertical_margin 或 @dimen/activity_horizo​​ntal_margin。我在上面放了一个示例代码。

【讨论】:

    猜你喜欢
    • 2011-11-24
    • 1970-01-01
    • 2015-08-06
    • 2023-01-22
    • 2016-11-19
    • 2014-04-17
    • 2020-11-27
    相关资源
    最近更新 更多