通过将边距设置为零,图像会填满屏幕。但是要将边距设置为 100,除了右侧之外,它都适合。为什么这样做?
ImageView imagen = new ImageView(this);
RelativeLayout relative = new RelativeLayout(this);
RelativeLayout.LayoutParams labelLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
relative.setLayoutParams(labelLayoutParams);
RelativeLayout rl = new RelativeLayout(this);
RelativeLayout.LayoutParams layoutImagenClicker = new RelativeLayout.LayoutParams
(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
layoutImagenClicker.setMargins(0, 0, 0, 0);
imagen.setBackgroundResource(R.drawable.barra_seek_bar);
imagen.setLayoutParams(layoutImagenClicker);
rl.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
rl.addView(imagen);
relative.addView(rl);
setContentView(relative);
ImageView imagen = new ImageView(this);
RelativeLayout relative = new RelativeLayout(this);
RelativeLayout.LayoutParams labelLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
relative.setLayoutParams(labelLayoutParams);
RelativeLayout rl = new RelativeLayout(this);
RelativeLayout.LayoutParams layoutImagenClicker = new RelativeLayout.LayoutParams
(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
layoutImagenClicker.setMargins(100, 100, 100, 100);
imagen.setBackgroundResource(R.drawable.barra_seek_bar);
imagen.setLayoutParams(layoutImagenClicker);
rl.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
rl.addView(imagen);
relative.addView(rl);
setContentView(relative);
具有相同填充的不同边距?
layoutImagenClicker.setMargins(0, 0, 0, 0);
layoutImagenClicker.setMargins(100, 100, 100, 100);
看这个!
layoutImagenClicker.setMargins(100, 100, 200, 100);
相同的结果集边距右 100 或 200。这是一个错误吗?