從網上找的一個信息,在此記錄一下 RelativeLayout insertLayout = (RelativeLayout)view1.findViewBy(R..screen);//screen是一個RelativeLayout 佈局的 ImageView imgApple2 = new ImageView(MainActivity.this); imgApple2.setBackgroundColor(Color.parseColor("#ffb6b4")); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(100, 100); layoutParams.topMargin=8; layoutParams.leftMargin=8; layoutParams.rightMargin=8; layoutParams.bottomMargin=8; insertLayout.addView(imgApple2,layoutParams);
//佈局文件android
<RelativeLayoutide
android:id="@+id/layout_order_menu_bottom_line"佈局
android:layout_width="match_parent"this
android:layout_height="wrap_content"spa
android:gravity="bottom" >it
</RelativeLayout>class