Gridlaylout Simple Layout

Source: Internet
Author: User

Package Com.example.gridlayout;import Android.app.activity;import android.os.bundle;import Android.view.gravity;import Android.widget.button;import android.widget.GridLayout; Public classMaingrid extends Activity {GridLayout grd; String[] Chas=Newstring[] {"7","8","9","*"              ,"4","5","6","/"              ,"1","2","3","+"              ,"0",".","=","-"                        }; @Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main_grid); GRD=(GridLayout) Findviewbyid (r.id.root);  for(intI=0; i<chas.length;i++) {Button bt=NewButton ( This);             Bt.settext (Chas[i]); Bt.settextsize ( +); Bt.setheight ( $); Gridlayout.spec Rowspec= Gridlayout.spec (I/4+2); //specify the column in which the component is locatedGridlayout.spec Columnspec = gridlayout.spec (i%4); Gridlayout.layoutparamsparams=Newgridlayout.layoutparams (Rowspec, Columnspec); //Specifies that the component fills the parent container                params. setgravity (Gravity.fill); Grd.addview (BT,params); }    }}
<?XML version= "1.0" encoding= "Utf-8"?><GridLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:rowcount= "6"Android:columncount= "4"Android:id= "@+id/root"    ><!--Define a text box that spans 4 columns and set the foreground color, background color, and other properties of the text box -<TextViewAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_columnspan= "4"android:textsize= "50SP"Android:layout_marginleft= "4px"Android:layout_marginright= "4px"android:padding= "5px"android:layout_gravity= "Right"Android:background= "#eee"Android:textcolor= "#000"Android:text= "0"/><!--Define a button that spans 4 columns -<ButtonAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_columnspan= "4"Android:text= "Clear"/></GridLayout>
<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.example.gridlayout"Android:versioncode= "1"Android:versionname= "1.0" >    <USES-SDKandroid:minsdkversion= "+"android:targetsdkversion= "+" />    <ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" >        <ActivityAndroid:name=". Maingrid "Android:label= "@string/app_name" >            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>    </Application></Manifest>

Gridlaylout Simple Layout

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.