Main.xml ....... ........
<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation= "Horizontal"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:background= "@drawable/background"
Android:id= "@+id/layout"
>
</LinearLayout>
Activi ......... ..............
Package com.example.ui;
Import Android.os.Bundle;
Import android.app.Activity;
Import Android.view.Menu;
Import Android.view.ViewGroup.LayoutParams;
Import Android.widget.ImageView;
Import Android.widget.LinearLayout;
public class Mainactivity extends Activity {
Private ImageView [] img=new imageview[4]; Declares an array that holds a ImageView component
Private int[] Imagepath=new int[]{//Declare and initialize an array that holds access to the picture
R.drawable.j1,r.drawable.j2,r.drawable.j3,r.drawable.w1
};
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
LinearLayout layout= (linearlayout) Findviewbyid (r.id.layout);//Get a linear layout manager defined in an XML file
for (int i=0;i<imagepath.length;i++) {//
Img[i]=new ImageView (this);//Create a ImageView component
Img[i].setimageresource (Imagepath[i]);//Specify the picture to display for the ImageView component
Img[i].setpadding (5, 5, 5, 5);//Set the inner margin of the ImageView component
Layoutparams params=new Layoutparams (253,148);//Set the width and height of the picture
Img[i].setlayoutparams (params);//Set layout parameters for ImageView components
Layout.addview (Img[i]);//Add the ImageView component to the layout manager
}
}
@Override
public boolean Oncreateoptionsmenu (Menu menu) {
Inflate the menu; This adds items to the action bar if it is present.
Getmenuinflater (). Inflate (R.menu.main, menu);
return true;
}
}
Effects such as:
Using the XML and Java code blending control UI Interface