Android : RelativeLayout alignment/positioning not working

on Sunday, September 7, 2014


I've had a look around, and not been able to find a fix to this problem. Yes it is something that has been asked before, but none of the solutions I've found has corrected my problem.

So basically, my problem is that I need two views to align to the right of their container, one next to the other. I can't stop them from overlapping however.



RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams((int) (screenWidth*0.30), LayoutParams.WRAP_CONTENT);
param.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
newSpinner.setLayoutParams(param);
newSpinner.setId(-101);

param = new RelativeLayout.LayoutParams((int) (screenWidth*0.10), LayoutParams.WRAP_CONTENT);
param.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
param.addRule(RelativeLayout.LEFT_OF, newSpinner.getId());
newButton.setLayoutParams(param);


The above code results in this: http://i.imgur.com/o1GlZLV.png



param.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);


While removing the above line results in this: http://i.imgur.com/25vlmrw.png


So what's the fix?


0 comments:

Post a Comment