【问题标题】:Padding is different between layout and app title布局和应用标题之间的填充不同
【发布时间】:2012-10-23 03:17:44
【问题描述】:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="6dp"
android:weightSum="1.0" >

<Button
    android:id="@+id/btnCreateNewMonth"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center_vertical|center"
    android:layout_weight="0.5"
    android:onClick="btnCreateNewMonth_clickHandler"
    android:paddingBottom="5dp"
    android:text="@string/btn_create_new_month" />

<Button
    android:id="@+id/btnLoadExistingMonth"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center_vertical|center"
    android:layout_weight="0.5"
    android:onClick="btnLoadExistingMonth_clickHandler"
    android:text="@string/btn_load_existing_month" />

   </LinearLayout>

所有边的内边距应为 6dp。但是在顶部,在应用标题和布局之间有一个较小的填充?!有什么解决办法??

谢谢。

【问题讨论】:

    标签: android layout padding title


    【解决方案1】:

    问题不在于填充,

    如果你深入布局,你会发现按钮占用区域和布局区域的区别。

    1. 按钮的背景源未完全占据右、左、下角的空间。

    2. 但是Button的Background源已经被覆盖并完全占据了顶部。

    3. 请注意,Button 的背景源是一个 9 补丁图像,具有透明背景。

    4. 在这种情况下,例如如果按钮的背景源没有占用的Gap是2dp的意思,

      Right , Left, Bottom 会有一个额外的 2dp 空间。但不在顶部。

      因此,使用 6dp 的填充,您将获得额外的 2dp 背景可见性,用于右、左、下角的两个按钮。

    因此,如果您的内边距值为 6dp ,那么您的布局背景可见性将在右、左、下角为 8dp,在顶部为 6dp。

    这是真正的问题。

    1. 如果更改按钮的背景颜色,则可以看到所有 4 个角的填充值均等。

    2. 如果您要为按钮创建图像背景,那么它应该同样创建,这与 android 默认按钮背景不同。

    因此解决方案是,您可以为按钮创建渐变背景,也可以为按钮创建新的图像文件。

    希望您能得到它,它将对您有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多