[Android] weather app layout exercise (2), androidapp

Source: Internet
Author: User

[Android] weather app layout exercise (2), androidapp

Exercise the GridView

MainActivity. java

Package com. example. weatherreport; import java. util. arrayList; import java. util. hashMap; import java. util. list; import java. util. map; import android. app. activity; import android. OS. bundle; import android. widget. gridView; import android. widget. simpleAdapter; public class MainActivity extends Activity {private GridView gv_airs; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); gv_airs = (GridView) findViewById (R. id. gv_airs); makeGridView ();}/*** assemble the GridView */private void makeGridView () {List <Map <String, String> data = new ArrayList <> (); map <String, String> item = null; item = new HashMap <> (); item. put ("title", "83"); item. put ("desc", "humidity (%)"); data. add (item); item = new HashMap <> (); item. put ("title", "11.3"); item. put ("desc", "visibility (km)"); data. add (item); item = new HashMap <> (); item. put ("title", "Level 2"); item. put ("desc", "southeast wind"); data. add (item); item = new HashMap <> (); item. put ("title", "weakest"); item. put ("desc", "UV"); data. add (item); item = new HashMap <> (); item. put ("title", "1005.5"); item. put ("desc", "pressure (mb)"); data. add (item); item = new HashMap <> (); item. put ("title", "22.4"); item. put ("desc", "somatosensory"); data. add (item); SimpleAdapter adapter = new SimpleAdapter (this, data, R. layout. main_grid_item, new String [] {"title", "desc"}, new int [] {R. id. TV _title, R. id. TV _desc}); gv_airs.setAdapter (adapter );}}

Activity_main.xml

<RelativeLayout xmlns: 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} "> <ImageView android: layout_width =" wrap_content "android: layout_height =" wrap_content "android: layout_marginLeft =" 10dp "android: layout_marginTop =" 10dp "android: src = "@ drawable/icon_home"/> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_centerHorizontal = "true" android: layout_marginTop = "12dp" android: text = "Beijing" android: textColor = "# FDFDFD"/> <ImageView android: 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"/> <TextView android: id = "@ + id/TV _number" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_centerHorizontal = "true" android: layout_marginTop = "70dp" android: text = "29" android: textColor = "# fff" android: textSize = "50sp"/> <TextView android: 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"/> <LinearLayout android: 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"> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_centerHorizontal = "true" android: text = "multi cloud" android: textColor = "# FDFDFD"/> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_centerHorizontal = "true" android: text = "|" android: textColor = "# bbb"/> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_centerHorizontal = "true" android: text = "" android: textColor = "# FDFDFD"/> </LinearLayout> <View android: 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"/> <GridView android: 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 "/> <View android: 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"?> <RelativeLayout xmlns: 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"> <LinearLayout android: 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"> <TextView android: id = "@ + id/TV _desc" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "humidity (%)" android: textColor = "# ddd" android: textSize = "12sp"/> <TextView android: id = "@ + id/TV _title" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "83" android: textColor = "# fff" android: textSize = "22sp"/> </LinearLayout> </RelativeLayout>

 

Related Article

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.