Android mobile guard-used by jiugongge, android jiugong

Source: Internet
Author: User

Android mobile guard-used by jiugongge, android jiugong

URL: http://www.cnblogs.com/wuyudong/p/5907736.html.

Use the GridView method. Similar to the ListView method, the number of columns (3 columns)

First add the GridView

<! -- Android: numColumns specifies the number of columns --> <! -- Android: verticalSpacing = "10dp" specifies the Vertical spacing of internal entries to 10dp --> <GridView android: id = "@ + id/gv_home" android: layout_width = "match_parent" android: layout_height = "match_parent" android: numColumns = "3" android: verticalSpacing = "10dp"> </GridView>

Data filling (Module name, module image)

Package com. wuyudong. mobilesafe. activity; import com. wuyudong. mobilesafe. r; import android. app. activity; import android. content. clipData. item; import android. OS. bundle; import android. view. view; import android. view. viewGroup; import android. widget. baseAdapter; import android. widget. gridView; import android. widget. imageView; import android. widget. textView; public class HomeActivity extends Activity {private GridView gv_home; private String [] mTitleStrs; private int [] mDrawableIds; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_home); initUI (); // Method for initializing data initData ();} private void initData () {// prepare data (text (9 groups ), image (9 images) mTitleStrs = new String [] {"mobile anti-theft", "Communication guard", "software management", "Process Management", "Traffic Statistics ", "cell phone Antivirus", "cache cleanup", "advanced tools", "setting Center"}; mDrawableIds = new int [] {R. drawable. home_safe, R. drawable. home_callmsgsafe, R. drawable. home_apps, R. drawable. home_taskmanager, R. drawable. home_netmanager, R. drawable. home_trojan, R. drawable. home_sysoptimize, R. drawable. home_tools, R. drawable. home_settings}; // The data adapter (equivalent to the ListView data adapter) gv_home.setAdapter (new MyAdapter ();} private void initUI () {gv_home = (GridView) findViewById (R. id. gv_home);} class MyAdapter extends BaseAdapter {@ Override public int getCount () {// total number of text sets = number of image sheets return mTitleStrs. length ;}@ Override public Object getItem (int position) {return mTitleStrs [position] ;}@ Override public long getItemId (int position) {return position ;} @ Override public View getView (int position, View convertView, ViewGroup parent) {View view = View. inflate (getApplicationContext (), R. layout. gridview_item, null); TextView TV _title = (TextView) view. findViewById (R. id. TV _title); ImageView iv_icon = (ImageView) view. findViewById (R. id. iv_icon); TV _title.setText (mTitleStrs [position]); iv_icon.setBackgroundResource (mDrawableIds [position]); return view ;}}}

Create a layout file gridview_item.xml

<? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: gravity = "center" android: orientation = "vertical"> <ImageView android: id = "@ + id/iv_icon" android: background = "@ drawable/ic_launcher" android: layout_width = "wrap_content" android: layout_height = "wrap_content"/> <TextView android: id = "@ + id/TV _title" android: text = "module title" android: textSize = "18sp" android: layout_width = "wrap_content" android: layout_height = "wrap_content"/> </LinearLayout>

The effect after running is as follows:

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.