[android] layout center

Android 2012. 12. 24. 00:42


ImageView in FrameLayout



ImageView iv = new ImageView(MainActivity.this);

iv.setImageDrawable(MainActivity.this.getResources().getDrawable(drawable.arrow));

LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

lp.width = 100;

lp.height = 30;

iv.setLayoutParams(lp);


float frame_center_x = frame.getWidth() /2;

float frame_center_y = frame.getHeight() /2;

iv.setX(frame_center_x - iv.getLayoutParams().width/2);

iv.setY(frame_center_y -  iv.getLayoutParams().height/2);


frame.addView(iv);





Posted by tenn
,