• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Creating a button using Java?

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..........
 
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
 
Back
Top Bottom