Instead of using RelativeLayout.WRAP_CONTENT for the width, you can use the actual number, which will be the new button width in pixels. Since you probably want the width in dp to be resolution independent, you probably need to convert dp to pixels using the following method:
public static int dpToPixels(Context context, float dp) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
source
share