手机卫士学习05-手机卫士主界面UI

制作的效果图:

手机卫士学习05-手机卫士主界面UI_第1张图片


activity_home.xml:




    

    


home_list.xml:




    

    


HomeActivity.java:

package com.itheima.mobilesafe;

import android.app.Activity;
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_list;
	private MyAdapter adapter;
	private static String[] names ={
		"手机防盗","通讯卫士","软件管理",
		"进程管理","流量统计","手机杀毒",
		"缓存清理","高级工具","设置中心"
	};
	private static int[] images ={
		R.drawable.safe,R.drawable.callmsgsafe,R.drawable.app,
		R.drawable.taskmanager,R.drawable.netmanager,R.drawable.trojan,
		R.drawable.sysoptimize,R.drawable.atools,R.drawable.settings
	};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home);
		
		gv_home_list =(GridView) findViewById(R.id.gv_home_list);
		adapter =new MyAdapter();
		gv_home_list.setAdapter(adapter);
	}
	
	private class MyAdapter extends BaseAdapter{

		@Override
		public int getCount() {
			return names.length;
		}
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			if(convertView == null){
				convertView =View.inflate(HomeActivity.this, R.layout.home_list, null);
			}
			ImageView iv_item = (ImageView) convertView.findViewById(R.id.iv_home_list);
			TextView tv_item = (TextView) convertView.findViewById(R.id.tv_home_list);
			iv_item.setImageResource(images[position]);
			tv_item.setText(names[position]);
			return convertView;
		}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}
		
	}
	
}


源码下载:http://yunpan.cn/cy6eERIt4QhbT  访问密码 a876


你可能感兴趣的:(android手机卫士)