Android : Unwanted spacing between android viewgroups added programmatically

on Thursday, April 16, 2015


I'm adding a RelativeLayout in a FrameLayout ( added in xml ) and I attach a LinearLayout in this RelativeLayout.


The problem is I get an unwanted left/right spacing/padding between the RelativeLayout and its child LinearLayout as you can see here from the uiautomator dump. The weird thing is that spacing is always 11 pixels from each side tested on emulator N5, N4, N7 images and Moto G and N4 devices. Thank you


enter image description here


The code is :



rlBottomBarContainer = new RelativeLayout(this);
rlBottomBarContainer.setId(R.id.bottomBarContainer);
rlBottomBarContainer.setClipToPadding(false);
rlBottomBarContainer.setClipChildren(false);
rlBottomBarContainer.setBackground(getResources().getDrawable(R.drawable.bara));

int topMargin = whiteTowerContainerHeight /2 + tower_height/2 + 100;
int containerHeight = whiteTowerContainerHeight - topMargin;
FrameLayout.LayoutParams containerParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
containerHeight);
containerParams.topMargin = topMargin;

rlBottomBarContainer.setLayoutParams(containerParams);
frameLayoutRoot.addView(rlBottomBarContainer); // parentLayout

llBottomBarContainer = new LinearLayout(this);
llBottomBarContainer.setId(R.id.upper_bottombar_ID);
llBottomBarContainer.setClipChildren(false);
llBottomBarContainer.setClipToPadding(false);
llBottomBarContainer.setBackgroundColor(Color.parseColor("#00FFFFFF"));
llBottomBarContainer.setOrientation(LinearLayout.HORIZONTAL);

RelativeLayout.LayoutParams bottomBarParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
getBottomBarTextSize());

llBottomBarContainer.setLayoutParams(bottomBarParams);
rlBottomBarContainer.addView(llBottomBarContainer);


As you can see from the code the LinearLayout is added with match_parent for the width. RelativeLayout width is from 0 to 720px but LinearLayout is from 11 to 709pixels.


0 comments:

Post a Comment