Layout_gravity center along with layout_marginRight question

I cannot get the reason there is a difference in the two views, only the difference is layout_gravity Center is missing in the second

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

0


source to share


2 answers


When you do android: layout_gravity = "top | center" I think margin_right makes the view to the left

enter image description here

Could it be?



Edited

I used your code to see and this is the result enter image description here

+2


source


enter image description here

here are my questions.

The reason for the extra 8dp difference in performance? not solutions



there is an underline under my words ..

  • I pictured it as a view with a black background.
  • with leftmargin 48dp.
  • but as you can see there is an additional 8dp.
  • I'm looking for the real reason.
  • there is no other way to figure it out.
  • check my link for more information.
-1


source







All Articles