layout_gravity center along with layout_marginRight issue

五迷三道 提交于 2020-02-02 16:26:07

问题


I am not able to get reason why there is difference in below two views, only difference is layout_gravity center is missing in second one

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


回答1:


When you're doing android:layout_gravity="top|center" I think that margin_right is making go the view to the left

Could that be it?

Edited

I used your code to see and this is the result




回答2:


here is my ques.

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

under my words there is an underline..

  • i represented it as a view with black background.
  • with leftmargin of 48dp.
  • but as you see there is an 8dp extra.
  • i am looking for a genuine reason.
  • not other ways to sort it out.
  • check my link for further details.


来源:https://stackoverflow.com/questions/31212020/layout-gravity-center-along-with-layout-marginright-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!