Search code examples
androidandroid-relativelayout

Android: Overriding RelativeLayout


My RelativeLayout has some padding, but for a certain SurfaceView I want it to have no padding. I set the padding to 0dp, yet it still follows the RelativeLayout. How do I override it?


Solution

  • if your root layout has set padding then even if you set 0dp padding to the child views the will have the padding due to root layout.use the nested layout and assign the padding to layouts you want.

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                              android:orientation="horizontal"
                              android:layout_width="fill_parent"
                              android:layout_height="wrap_content">
    
    <RelativeLayout><surfaceview></surfaceview></RelativeLayout>  //add padding here if you want
    
    <RelativeLayout><Button></Button></RelativeLayout>  //do not add padding here if you do not want
    </RelativeLayout>