Reputation: 4300
I want to doing a relative layout programmatically and set android:layout_widht=60 android:layout_height=60.When i doing programmatically it is fill all screen? How can i do that?
my code:`
RelativeLayout relativeLayout=new RelativeLayout(getContext());
RelativeLayout.LayoutParams rel_btn = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rel_btn.height = 60;
rel_btn.width = 60;
relativeLayout.setLayoutParams(rel_btn);
this.setBackgroundResource(com.example.R.drawable.line);`
screen:
Upvotes: 3
Views: 10514
Reputation: 671
btn.getLayoutParams().width = width;
btn.getLayoutParams().height = height;
in fact, just use
RelativeLayout.LayoutParams rel_btn = new RelativeLayout.LayoutParams(
60, 60);
that's OK. the problem maybe the background pic stretch the button
Upvotes: 7