Mainly practice the GridView
Mainactivity.java
PackageCom.example.weatherreport;Importjava.util.ArrayList;ImportJava.util.HashMap;Importjava.util.List;ImportJava.util.Map;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.widget.GridView;ImportAndroid.widget.SimpleAdapter; Public classMainactivityextendsActivity {PrivateGridView Gv_airs; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Gv_airs=(GridView) Findviewbyid (r.id.gv_airs); Makegridview (); } /*** Assemble GridView*/ Private voidMakegridview () {List<map<string, string>> data=NewArraylist<>(); Map<String,String> item=NULL; Item=NewHashmap<>(); Item.put ("title", "83"); Item.put ("desc", "humidity (%)"); Data.add (item); Item=NewHashmap<>(); Item.put ("title", "11.3"); Item.put ("desc", "visibility (km)"); Data.add (item); Item=NewHashmap<>(); Item.put ("title", "Level 2"); Item.put ("Desc", "Southeast Wind"); Data.add (item); Item=NewHashmap<>(); Item.put ("title", "Weakest"); Item.put ("desc", "Ultraviolet"); Data.add (item); Item=NewHashmap<>(); Item.put ("title", "1005.5"); Item.put ("Desc", "Barometric pressure (MB)"); Data.add (item); Item=NewHashmap<>(); Item.put ("title", "22.4"); Item.put ("desc", "Body Feeling"); Data.add (item); Simpleadapter Adapter=NewSimpleadapter ( This, data, R.layout.main_grid_item,Newstring[]{"title", "Desc"},New int[]{r.id.tv_title,r.id.tv_desc}]; Gv_airs.setadapter (adapter); }}
Activity_main.xml
<Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:background= "#3186D9"Tools:context= "${relativepackage}.${activityclass}" > <ImageViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_marginleft= "10DP"Android:layout_margintop= "10DP"android:src= "@drawable/icon_home" /> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_centerhorizontal= "true"Android:layout_margintop= "12DP"Android:text= "Beijing"Android:textcolor= "#FDFDFD" /> <ImageViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentright= "true"Android:layout_marginright= "10DP"Android:layout_margintop= "10DP"android:src= "@drawable/icon_more" /> <TextViewAndroid:id= "@+id/tv_number"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_centerhorizontal= "true"Android:layout_margintop= "70DP"Android:text= "$"Android:textcolor= "#fff"android:textsize= "50SP" /> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_aligntop= "@id/tv_number"Android:layout_torightof= "@id/tv_number"Android:text="°"Android:textcolor= "#FDFDFD"android:textsize= "30SP" /> <LinearLayoutAndroid:id= "@+id/ll_weather"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_below= "@id/tv_number"Android:layout_centerhorizontal= "true"android:orientation= "Horizontal" > <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_centerhorizontal= "true"Android:text= "Cloudy"Android:textcolor= "#FDFDFD" /> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_centerhorizontal= "true"Android:text=" | "Android:textcolor= "#bbb" /> <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_centerhorizontal= "true"Android:text= "Excellent Air"Android:textcolor= "#FDFDFD" /> </LinearLayout> <ViewAndroid:id= "@+id/gv_airs_top"Android:layout_width= "Match_parent"Android:layout_height= "1DP"Android:layout_below= "@id/ll_weather"Android:layout_margintop= "20DP"Android:background= "#ddd" /> <GridViewAndroid:id= "@+id/gv_airs"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_below= "@id/gv_airs_top"Android:background= "#ddd"android:horizontalspacing= "1DP"Android:listselector= "@android: Color/transparent"Android:numcolumns= "3"android:verticalspacing= "1DP" /> <ViewAndroid:layout_width= "Match_parent"Android:layout_height= "1DP"Android:layout_below= "@id/gv_airs"Android:background= "#ddd" /></Relativelayout>
Main_grid_item.xml
<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:background= "#3186D9"Android:layout_marginleft= "1DP" > <LinearLayoutAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:paddingtop= "25DP"Android:paddingbottom= "25DP"android:layout_centerinparent= "true"android:gravity= "Center"android:orientation= "vertical" > <TextViewAndroid:id= "@+id/tv_desc"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Humidity (%)"Android:textcolor= "#ddd"android:textsize= "12SP" /> <TextViewAndroid:id= "@+id/tv_title"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "The "Android:textcolor= "#fff"android:textsize= "22SP" /> </LinearLayout></Relativelayout>
[Android] weather app layout exercises (ii)