Set Button Width And Height Progamitically

I am creating an extension in which i need to set button width and height
but problem is that it is not working . it is taking full parent in arrangement
i tried by two codes
button.setWidth(width);
button.setHeight(height);

and other one
myButton.setText(text);
android.widget.LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width , height);
myButton.setLayoutParams(lp);
but not working
can anyone give me correct snippet?

We can try to help only if you show the full code.

  @SimpleFunction(description="Add A Button")
  public void AddButton(int id , String text , int width , int height){
    ViewGroup myViewGroup = (ViewGroup)layout.getView();
    Button myButton = new Button(activity);
    myButton.setId(id);
   myButton.setText(text);
android.widget.LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width , height);
myButton.setLayoutParams(lp);
    myViewGroup.addView(myButton);
   }

button is creating and everything is working just the width and height ones is not working

Is the code getting compiled with no errors ?

yes it is getting complied
and i checked in creator

Try changing

android.widget.LinearLayout.LayoutParams

to

android.widget.ViewGroup.LayoutParams

ok let me try

done perfect!

1 Like

thanks so much

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.