Thursday, 17 January 2013

Dynamically Relative Layout at Runtime in android

Relative Layout at Runtime in android.



              RelativeLayout relParent = new RelativeLayout(HomeScreen.this);
              RelativeLayout.LayoutParams rlparent = new RelativeLayout.LayoutParams(
                           RelativeLayout.LayoutParams.FILL_PARENT,
                           RelativeLayout.LayoutParams.FILL_PARENT);
              relParent.setLayoutParams(rlparent);

              RelativeLayout relTop = new RelativeLayout(HomeScreen.this);
              RelativeLayout.LayoutParams rlpTop = new RelativeLayout.LayoutParams(
                           RelativeLayout.LayoutParams.FILL_PARENT,
                           RelativeLayout.LayoutParams.WRAP_CONTENT);
              rlpTop.addRule(RelativeLayout.ALIGN_PARENT_TOP);

              RelativeLayout.LayoutParams rlpBottom = new RelativeLayout.LayoutParams(
                           RelativeLayout.LayoutParams.FILL_PARENT,
                           RelativeLayout.LayoutParams.WRAP_CONTENT);
              rlpBottom.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

              relTop.setLayoutParams(rlpTop);
              relBottom.setLayoutParams(rlpBottom);

              TextView txtTitle = new TextView(HomeScreen.this);
              RelativeLayout.LayoutParams relParam = new RelativeLayout.LayoutParams(
                           RelativeLayout.LayoutParams.WRAP_CONTENT,
                           RelativeLayout.LayoutParams.WRAP_CONTENT);

              relParam.addRule(RelativeLayout.CENTER_IN_PARENT);
              txtTitle.setText("HomeScreen");
              txtTitle.setLayoutParams(relParam);
              txtTitle.setTextColor(Color.BLUE);
              txtTitle.setTextSize(18);

              relTop.addView(txtTitle);

              relParent.addView(relTop);
              relParent.addView(relBottom);

              setContentView(relParent);


It does not require any layout.xml file becuase all gui is using code.
In Relative Layout , we use RelativeLayout.LayoutParams same way
In Linear Layout , we use LinearLayout.LayoutParams.

 Our new android application for EGreeting.Have a look to it. 

 The Greetings Android Application 



NovaRadix Android Application Development Team
NovaRadix Technology
WWW.NOVARADIX.COM

1 comment:

Call web services easily

get source code from here, Download