RelativeLayout-CenterInParent和marginTop [英] RelativeLayout - CenterInParent and marginTop

查看:259
本文介绍了RelativeLayout-CenterInParent和marginTop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下XML:

<RelativeLayout android:id="@+id/cover_box"
    android:layout_width="wrap_content" android:layout_height="wrap_content">
    <ImageView android:id="@+id/cover"
        android:layout_width="wrap_content" android:layout_height="wrap_content" />
    <ImageView android:id="@+id/download" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:src="@drawable/mark_download"
        android:layout_centerInParent="true" android:layout_marginTop="90px" />
</RelativeLayout>

但是看起来好像marginTop被忽略了.

But it's look's like the marginTop is being ignored.

推荐答案

在父级中使用center时,视图将直接置于中心.仅当对象距视图顶部90像素以内时,页边距顶部才会起作用.因此,将居中的视图向下推以在其顶部至少保留90px的空间.因此,它不会被忽略,但不会发挥您认为应该具有的效果.

When you use center in parent the view is put directly in the center. The margin top will only come into play if an object is within 90px of the top of your view. Thus pushing the centered view down to keep at least 90px of space on top of it. So it isn't being ignored but it is not having the effect that you think it should have.

这篇关于RelativeLayout-CenterInParent和marginTop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆