layout_gravity center以及layout_marginRight问题

时间:2015-07-03 17:44:20

标签: android android-layout android-view

我无法理解为什么以下两个视图存在差异,只有差异是第二个缺少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"
        />

enter image description here

<?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"
        />

enter image description here

2 个答案:

答案 0 :(得分:2)

当你在做 android:layout_gravity =“top | center”时,我认为 margin_right 正在向左转移视图

enter image description here

可能是吗?

<强>被修改

我用你的代码看,这是结果 enter image description here

答案 1 :(得分:-1)

enter image description here

这是我的问题。

Reason behind extra 8dp margin in a view ? not ways to solve

在我的话下有一个下划线..

  • 我把它表示为黑色背景的视图。
  • with leftmargin of 48dp。
  • 但正如你所看到的那样,还有8dp。
  • 我正在寻找一个真正的理由。
  • 没有其他方法可以解决这个问题。
  • 查看我的链接以获取更多详细信息。