Here is the solution.
The XML code:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id = "@+id/rootView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
The Java code :
View myView = new View(this);
LayoutParams layoutParams=new LayoutParams(320,240);
layoutParams.leftMargin = 50;
layoutParams.topMargin = 60;
myView.setLayoutParams(layoutParams);
myView.setBackgroundColor(Color.YELLOW);
rootView.addView( myView );
View myView2 = new View(this);
layoutParams=new LayoutParams(320,240);
layoutParams.leftMargin = 200;
layoutParams.topMargin = 120;
myView2.setLayoutParams(layoutParams);
myView2.setBackgroundColor(Color.BLUE);
rootView.addView( myView2 );
And we need to import
import android.widget.RelativeLayout.LayoutParams;
At the beginning I used FrameLayout instead of RelativeLayout. It seems it is not possible to programmatically set the position of a view with Android 2.2 if the parent layout is a FrameLayout.
Thanks a lot for your help.