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

パディンゼロ画像


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に設定します。これはバグですか?

4

1 に答える 1

1

RelativeLayoutラッパーでパディングを設定してから、imageviewの余白を削除してみてください。あなたの元の質問に関しては、なぜそれが台無しになるのか分かりませんが、マージンからパディングに移動することは私がいつも好むものです...

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 に答える