Delete image from parent on Android:
View myView = findViewById(R.id.my_view);
ViewGroup parent = (ViewGroup) myView.getParent();
parent.removeView(myView);
Android removes all child views:
LinearLayout formLayout = (LinearLayout)findViewById(R.id.formLayout);
formLayout.removeAllViews();
Add to parents on Android:
Button myButton = new Button(getApplicationContext());
myButton.setLayoutParameters(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT));
myLayout.addView(myButton);
you can use:
LinearLayout.LayoutParams.FILL_PARENT
or
LinearLayout.LayoutParams.WRAP_CONTENT
source
share