Introduced in Android 4.0,the Grid Layout uses a rectangular grid of infinitely thin lines to layout Views in a series of rows and coloumns.The Grid Layout is increible,flexible and can be used to greatly simplify layouts and reduce, eliminate complex nesting.
Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?> <GridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridView1" android:numColumns="auto_fit" android:gravity="center" android:columnWidth="50dp" android:stretchMode="columnWidth" android:layout_width="fill_parent" android:layout_height="fill_parent" > </GridView>
Main Activity.Java
package info.siddhu.gridlayout; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.GridView; import android.app.Activity; public class MainActivity extends Activity { GridView gridView; static final String[] numbers = new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); gridView = (GridView) findViewById(R.id.gridView1); ArrayAdapteradapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, numbers); gridView.setAdapter(adapter); } }
No comments:
Post a Comment