1. Download our Official Android App: Forums for Android!

Apps Creating a button using Java?

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

  1. soniamca17

    soniamca17 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    May 27, 2011

    May 27, 2011
    1
    0
    5
    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..........
     

    Advertisement

  2. Smoker

    Smoker Newbie
    Rank:
    None
    Points:
    15
    Posts:
    15
    Joined:
    May 25, 2011

    May 25, 2011
    15
    0
    15
    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
     

Share This Page

Loading...