RelativeLayout layout = findViewById(R.id.myRelativeLayout); TextView textView = new TextView(this); // 'this' is your activity context textView.setText("Hello World"); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT ); params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); layout.addView(textView, params);In this example, we first get a reference to our RelativeLayout using its ID. Then, we create a new TextView and set its text to "Hello World". Next, we create some layout parameters that specify the width and height of the TextView and that it should be centered in the parent RelativeLayout. Finally, we add the TextView to the RelativeLayout by calling the addView() method on the layout. Package Library: The package library for RelativeLayout is android.widget.