Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative Layout width/height is not work programmatically?

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: enter image description here

like image 556
DuyguK Avatar asked Mar 07 '26 01:03

DuyguK


1 Answers

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

like image 120
JohnCookie Avatar answered Mar 09 '26 19:03

JohnCookie