I have tried to align 5 buttons in a LinearLayout
with equal distance, everything looks good except the previous/next button, they have a bigger width.
I am setting everything programmatically like this:
LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(width, height, 1f);
buttonParams.gravity = Gravity.CENTER;
next.setBackground(android.support.v4.content.res.ResourcesCompat.getDrawable(getResources(), R.drawable.skipnext, null));
previous.setBackground(android.support.v4.content.res.ResourcesCompat.getDrawable(getResources(), R.drawable.skipprevious, null));
shuffle.setButtonDrawable(android.support.v4.content.res.ResourcesCompat.getDrawable(getResources(), R.drawable.shuffle, null));
repeat.setButtonDrawable(android.support.v4.content.res.ResourcesCompat.getDrawable(getResources(), R.drawable.repeat, null));
buttonsLayout.addView(repeat, buttonParams);
buttonsLayout.addView(previous, buttonParams);
buttonsLayout.addView(morphButton, buttonParams);
buttonsLayout.addView(next, buttonParams);
buttonsLayout.addView(shuffle, buttonParams);
LinearLayout.LayoutParams buttonsParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
buttonsParams.gravity = Gravity.CENTER;
buttonsParams.setMargins(0, marginTop, 0, marginBottom);
addView(buttonsLayout, buttonsParams);
buttonsLayout.setWeightSum(5);
buttonsLayout.setGravity(Gravity.CENTER);