Puede usar RelativeLayout. Digamos que usted quería una ImageView de 30x40 en la posición (50,60) dentro de su diseño. En algún lugar de su actividad:
// Some existing RelativeLayout from your layout xml
RelativeLayout rl = (RelativeLayout) findViewById(R.id.my_relative_layout);
ImageView iv = new ImageView(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(30, 40);
params.leftMargin = 50;
params.topMargin = 60;
rl.addView(iv, params);
Más ejemplos:
coloca dos 30x40 ImageViews (uno amarillo, uno rojo) en (50,60) y (80,90), respectivamente:
RelativeLayout rl = (RelativeLayout) findViewById(R.id.my_relative_layout);
ImageView iv;
RelativeLayout.LayoutParams params;
iv = new ImageView(this);
iv.setBackgroundColor(Color.YELLOW);
params = new RelativeLayout.LayoutParams(30, 40);
params.leftMargin = 50;
params.topMargin = 60;
rl.addView(iv, params);
iv = new ImageView(this);
iv.setBackgroundColor(Color.RED);
params = new RelativeLayout.LayoutParams(30, 40);
params.leftMargin = 80;
params.topMargin = 90;
rl.addView(iv, params);
Lugares uno 30x40 ImageView amarilla al (50,60) y otro ImageView rojo 30x40 < 80,90>relativa a ImageView amarilla:
RelativeLayout rl = (RelativeLayout) findViewById(R.id.my_relative_layout);
ImageView iv;
RelativeLayout.LayoutParams params;
int yellow_iv_id = 123; // Some arbitrary ID value.
iv = new ImageView(this);
iv.setId(yellow_iv_id);
iv.setBackgroundColor(Color.YELLOW);
params = new RelativeLayout.LayoutParams(30, 40);
params.leftMargin = 50;
params.topMargin = 60;
rl.addView(iv, params);
iv = new ImageView(this);
iv.setBackgroundColor(Color.RED);
params = new RelativeLayout.LayoutParams(30, 40);
params.leftMargin = 80;
params.topMargin = 90;
// This line defines how params.leftMargin and params.topMargin are interpreted.
// In this case, "<80,90>" means <80,90> to the right of the yellow ImageView.
params.addRule(RelativeLayout.RIGHT_OF, yellow_iv_id);
rl.addView(iv, params);
también ven 'view.setTranslationX()' 'o view.offsetLeftAndRight()' –
Acabo de liberar una biblioteca que puede haber sido de interés aquí. github.com/ManuelPeinado/ImageLayout – Manuel
Esto es muy difícil porque el 99.9% del tiempo el posicionamiento absoluto es una mala idea en Android. Si está escribiendo una aplicación que * SOLO * se ejecutará en un dispositivo físico, esto podría funcionar, pero generalmente no es una suposición segura. Por ejemplo, no cargue esto a google play.Funciona bien en iOS porque solo hay un puñado de dispositivos de hardware, y puedes construir un guión gráfico personalizado para cada uno. – edthethird