If you haven't added the view to any parent container, or havent called setLayoutParams manually, then getLayoutParams() will return null.
Make soure you call viewDynamic.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
before you call viewDynamic.getLayoutParams();
, or add the view to a container, so LayoutParams will be generated for the view.
I suggest you add your View like this:
viewDynamic = new TextView(getApplicationContext());
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relative);
RelativeLayout.LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params.addRule(RelativeLayout.ABOVE,userEditTxt.getId());
viewDynamic.setText(userEditTxt.getText());
viewDynamic.setTextColor(Color.RED);
viewDynamic.setTextScaleX(2);
viewDynamic.setTextSize(20);
viewDynamic.setPadding(10, 10, 10, 10);
relativeLayout.addView(viewDynamic,params);//you attach params to your View here