Hi I am developing android application. I am creating view programatically.In my layout I have relative layout as root element. I tried to set margin to my root relative layout. But I am not able to do that. I tried this in following way:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout relativeLayout = new RelativeLayout(this);
RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
rlp.setMargins(100,100,100,100);
relativeLayout.setLayoutParams(rlp);
relativeLayout.setBackgroundColor(getResources().getColor(R.color.colorAccent3));
setContentView(relativeLayout);
}
}
above code add relative layout to my activity. But not considering margins. Need some help. Thank you.