user3439710
user3439710

Reputation: 43

How to create a linear layout with textview and image button dynamically

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

Upvotes: 2

Views: 1131

Answers (1)

srbyk1990
srbyk1990

Reputation: 411

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);

Upvotes: 1

Related Questions