So I’m creating ImageView and TextView in the runtime and I want the TextView to be placed right of the ImageView.
I’m trying this simple code:
private void loadContent(Module module) {
this.removeAllViewsInLayout();
this.addView(getModuleIconView(module));
this.addView(getModuleNameView(module));
}
private ImageView getModuleIconView(Module module) {
ImageView view = new ImageView(context);
view.setImageResource(module.getIconResId());
android.view.ViewGroup.LayoutParams params = new LayoutParams(120, 120);
view.setLayoutParams(params);
view.setId(1); //seting some id for the view
return view;
}
private TextView getModuleNameView(Module module) {
TextView view = new TextView(context);
view.setText(module.getName());
params.addRule(RelativeLayout.RIGHT_OF, 1); //hoping for view to be placed right of the ImageView which id was set to 1
return view;
}
What Do I do wrong here? The TextView is placed on my ImageView ignoring the RIGHT_OF
Need to mention the class inherits from RelativeLayout
It was my stupid mistake. Third method leaks setLayoutParams
So correct method body is: