I have a very simple layout that I can\'t make it looks like I want. It\'s a LinearLayout with a button and a Switch. I want them to show one above the other, but I want their w
Button button = (Button) findViewById(R.id.share_button);
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int width = displaymetrics.widthPixels;
int buttonWidth = width/2;
set this buttonWidth
to your button like button.setWidth(buttonWidth);