Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Mugurell/76ecf66a7f09facf5aa578928103dc13 to your computer and use it in GitHub Desktop.
Save Mugurell/76ecf66a7f09facf5aa578928103dc13 to your computer and use it in GitHub Desktop.
// Create the widget
final DatePicker input = new DatePicker(context);
....
final View view = (View) input;
// Wrap the widget in a LinearLayout to prevent it from being chopped
final LinearLayout widgetWrapper = new LinearLayout(context);
final LinearLayout.LayoutParams parentParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
parentParams.gravity = Gravity.CENTER;
view.setLayoutParams(parentParams);
widgetWrapper.addView(v);
// Add the wrapped view to the AlertDialog
// Impossibility to scroll certain layouts still exists
AlertDialog.Builder builder = new AlertDialog.Builder(context);
....
builder.setView(widgetWrapper);
builder.create().show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment