2

通过将边距设置为零,图像会填满屏幕。但是要将边距设置为 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);
    

paddins 零图像


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);

paddins 图片一百


具有相同填充的不同边距?

layoutImagenClicker.setMargins(0, 0, 0, 0);
layoutImagenClicker.setMargins(100, 100, 100, 100);

看这个!

layoutImagenClicker.setMargins(100, 100, 200, 100);

一只忙碌的猫

相同的结果集边距右 100 或 200。这是一个错误吗?

4

1 回答 1

1

尝试在 RelativeLayout 包装器上设置填充,然后删除图像视图上的边距。至于你原来的问题,我不知道它为什么会搞砸,但从边距到填充是我一直喜欢的......

ImageView imagen = new ImageView(this);
RelativeLayout relative = new RelativeLayout(this);
RelativeLayout.LayoutParams labelLayoutParams = new RelativeLayout.LayoutParams
        (LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

// Padding on the RelativeLayout
relative.setPadding(100,100,100,100);

relative.setLayoutParams(labelLayoutParams);
RelativeLayout rl = new RelativeLayout(this);
RelativeLayout.LayoutParams layoutImagenClicker = new RelativeLayout.LayoutParams
         (RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);

// Remove the margin on the child
//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);

祝你好运

于 2012-05-16T16:03:08.227 回答