あなたはこのビューに動的にビューを追加したい
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
IS-あなたのルートXMLと仮定する。次に、親のレイアウトパラメータを子に設定し、他のすべてのプロパティを設定します。最後に、ビューをルートに追加して楽しんでください。あなたの活動にthis-
LinearLayout rootLayout = (LinearLayout) findViewById(R.id.root_layout);
TextView textView = new TextView(context);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.CENTER;
textView.setLayoutParams(layoutParams);
textView.setGravity(Gravity.CENTER);
textView.setText("Hello");
rootLayout.addView(textView);
のような/断片コードを使用注:ルートレイアウトがRelativeLayoutは、それに応じて他の人のためRelativeLayout.LayoutParamsを使用している場合。