2

i want to create a linear layout where inside it it has text view and image button. And i want to create it dynamically.

1

1 Answer 1

1
LinearLayout layoutSection = new LinearLayout(getActivity());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
params.gravity = Gravity.CENTER;
params.setMargins(5,5,5,5);
imageView.setImageResource(R.drawable.image);
imageView.setLayoutParams(params);
TextView textView = newTextView(getActivity());
TextView.setText(("Enter text here");
layoutSection.addView(textView);
layoutSection.addView(imageView);
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you it worked. But how can i change the orientation of the linear layout?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.