layout_gravity 中心和 layout_marginRight 问题

layout_gravity center along with layout_marginRight issue

我无法理解以下两个视图存在差异的原因,唯一的区别是 layout_gravity center 在第二个

中丢失
<?xml version="1.0" encoding="utf-8"?>
<View
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_gravity="top|center"
    android:layout_height="10dp"
    android:layout_marginRight="100dp"
    android:background="@android:color/holo_red_dark"
        />

<?xml version="1.0" encoding="utf-8"?>
<View
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_gravity="top"
    android:layout_height="10dp"
    android:layout_marginRight="100dp"
    android:background="@android:color/holo_red_dark"
        />

当你做 android:layout_gravity="top|center" 我认为 margin_right 正在向左移动视图

难道是这样吗?

已编辑

我用你的代码看了,结果是这样的

这是我的问题。

我的话下面有下划线..

  • 我将其表示为黑色背景的视图。
  • 左边距为 48dp。
  • 但如您所见,多了 8dp。
  • 我正在寻找一个真正的理由。
  • 没有其他方法可以解决。
  • 查看我的 link 了解更多详情。