Code example for ScrollView

Methods: addView, setLayoutParams

0
	private static View createDialogView(Context context) {
		LinearLayout llRoot = new LinearLayout(context);
		llRoot.setOrientation(LinearLayout.VERTICAL);
		llRoot.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
 
		ScrollView sv = new ScrollView(context);
		sv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1));
 
		LinearLayout llContent = new LinearLayout(context);
		llContent.setOrientation(LinearLayout.VERTICAL);
		llContent.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		llContent.setPadding(10, 0, 10, 0);
 
		LinearLayout llTop = new LinearLayout(context);
		llTop.setOrientation(LinearLayout.VERTICAL);
 
		descriptionTV = new TextView(context);
		descriptionTV.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		descriptionTV.setTextColor(Color.WHITE);
		descriptionET = new EditText(context);
		descriptionET.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		descriptionET.setMinLines(2);
		descriptionET.setMaxLines(2);
		descriptionET.setInputType(InputType.TYPE_CLASS_TEXT
				| InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
				| InputType.TYPE_TEXT_FLAG_AUTO_CORRECT );
 
		subjectTV = new TextView(context);
		subjectTV.setText("Subject:");
		subjectTV.setTextColor(Color.WHITE);
		subjectET = new EditText(context);
		subjectET.setSingleLine(true);
		subjectET.setInputType(InputType.TYPE_CLASS_TEXT
				| InputType.TYPE_TEXT_FLAG_CAP_WORDS
				| InputType.TYPE_TEXT_FLAG_AUTO_CORRECT );
 
		emailTV = new TextView(context);
		emailTV.setText("E-Mail:");
		emailTV.setTextColor(Color.WHITE);
		emailET = new EditText(context);
		emailET.setSingleLine(true);
		emailET.setInputType(InputType.TYPE_CLASS_TEXT
				| InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS );
 
		LinearLayout llBottom = new LinearLayout(context);
		llBottom.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
 
		TextView poweredByTV = new TextView(context);
		poweredByTV.setText("Powered By");
		poweredByTV.setPadding(0, 0, 10, 0);
		poweredByTV.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
		poweredByTV.setGravity(Gravity.CENTER_VERTICAL);
 
		ImageView poweredByIV = new ImageView(context);
		InputStream in = ZendeskDialog.class.getResourceAsStream("/com/zendesk/zendesk.png");
		Bitmap poweredBy = BitmapFactory.decodeStream(in);
		poweredByIV.setImageBitmap(poweredBy);
 
		LinearLayout llButton = new LinearLayout(context);
		llButton.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
		llButton.setOrientation(LinearLayout.HORIZONTAL);
		llButton.setBackgroundColor(0xFFBDBDBD);
		llButton.setPadding(0, 4, 0, 0);
 
		Button submit = new Button(context);
		submit.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1));
		submit.setText("Submit Query");
		submit.setId(DialogInterface.BUTTON1);
		submit.setOnClickListener(buttonListener);
 
		Button cancel = new Button(context);
		cancel.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1));
		cancel.setText("Cancel");
		cancel.setId(DialogInterface.BUTTON2);
		cancel.setOnClickListener(buttonListener);
 
		llRoot.addView(sv);
		llRoot.addView(llButton);
 
		sv.addView(llContent);
 
		llContent.addView(llTop);
		llContent.addView(llBottom);
 
		llTop.addView(descriptionTV);