Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 11

LAYOUTS IN ANDROID

The most commonly used Layouts are LinearLayout TableLayout RelativeLayout Framelayout

LinearLayout
Aligns all children in a single direction vertically or horizontally Can be defined by orientation attribute

TableLayout
Positions its children into rows and columns do not display border lines for their rows, columns, or cells

RelativeLayout
lets child views specify their position relative to the parent view or to each other (specified by ID)

FrameLayout
Layout that acts as a view frame to display a single object.

Creating layout using Linearlayout(xml file)

Creating layout using Linearlayout(java file)


Button b1=(Button)findViewById(R.id.button1); final CheckBox ck=(CheckBox)findViewById(R.id.checkBox1); final TextView tv=(TextView)findViewById(R.id.textView1);

b1.setOnClickListener(new View.OnClickListener(){ public void onClick(View v) { // TODO Auto-generated method stub if(ck.isChecked()) { String s="THANKS"; tv.setText(s); }
else { String s1="Please check the checkbox"; tv.setText(s1); } } });

Output of LinearLayout

Creating TableLayout(xml file)


Graphical representation of TableLayout in xml file

We can look the hierarchyof the table layout in the outline window

Output of the TableLayout

The output of the above TableLayout is as shown

You might also like