1. Are you ready for the Galaxy S20? Here is everything we know so far!

Creating a button using Java?

Discussion in 'Android Development' started by soniamca17, May 27, 2011.

  1. soniamca17

    soniamca17 Lurker
    Thread Starter

    I am developing one android app. I want create button at run time in that app using java code. I am able to create the button with below code-
    btn = new Button(this);
    btn.setText("Hello Button");
    RelativeLayout.LayoutParams paramsd = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    paramsd.height = 60;
    paramsd.width = 60;
    btn.setLayoutParams(paramsd);
    addContentView(btn,paramsd);

    By above code button is successfully created at the top-left corner. I am trying to align in the bottom corner using-
    paramsd.addRule(RelativeLayout.ALIGN_BOTTOM);

    But it is not getting aligned Please help me to get this sorted..........
     



    1. Download the Forums for Android™ app!


      Download

       
  2. Smoker

    Smoker Newbie

    You should do all your widget alignment, etc. in the layout file. But, if you want to do it in code, then try using RelativeLayout.ALIGN_PARENT_BOTTOM. The ALIGN_BOTTOM flag is used when you're referencing another widget for alignment.

    Smoker
     
Loading...
Similar Threads - Creating button using
  1. soulartist
    Replies:
    14
    Views:
    563
  2. Relaxing Leg
    Replies:
    0
    Views:
    450
  3. Sajivjess
    Replies:
    1
    Views:
    522
  4. RicardoM
    Replies:
    1
    Views:
    552
  5. My project
    Replies:
    9
    Views:
    746
  6. grizmixstir
    Replies:
    3
    Views:
    1,046
  7. kdmoore
    Replies:
    3
    Views:
    1,180
  8. cwg01
    Replies:
    3
    Views:
    2,903
  9. kumaranil13k
    Replies:
    4
    Views:
    1,130
  10. 5g Moto Android 11
    Replies:
    2
    Views:
    2,337

Share This Page

Loading...