bottom margin or padding doesn't work in relative layout in xml on android

梦想与她 提交于 2019-12-05 01:10:20
Android Stack

you can use this its work with me :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">  

     <ImageView
         android:id="@+id/imageView1"
         android:layout_width="50dp"
         android:layout_height="50dp"
         android:layout_alignParentLeft="true"
         android:layout_alignParentTop="true"
         android:layout_marginLeft="15dp"
         android:layout_marginTop="15dp" />

</RelativeLayout>

hope this helps.

For anyone else who is looking for a solution to this - from the docs:

http://developer.android.com/reference/android/widget/RelativeLayout.html

"Note that you cannot have a circular dependency between the size of the RelativeLayout and the position of its children. For example, you cannot have a RelativeLayout whose height is set to WRAP_CONTENT and a child set to ALIGN_PARENT_BOTTOM."

It seems also that there is some odd behavior if you put a relativeView inside of a scrollview.

In my case I had set the relativeLayout to wrap_content and then tried to add marginBottom to an ImageView with the ALIGN_PARENT_BOTTOM attribute. When I set the height explicitly it finally worked.

I suggest you to use LinearLayout... Or you can try to remove the attribute: android:layout_alignParentLeft="true"

If you want to center the view in a RelativeLayout you can use:

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