Android---launcher学习
来源:互联网 发布:大型网络钓鱼游戏 编辑:程序博客网 时间:2024/05/17 23:45
今天看到http://www.bangchui.org/read.php?tid=11761介绍有关launcher的内容,就想模仿的做一下,结果发现,就这有图标,没应用的名字怪怪的,于是做了改进。。
布局文件两个一个是main.xml,几乎没改动。。。
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><GridViewandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:numColumns="4"android:id="@+id/apps_list"></GridView></LinearLayout>
自己写了个item的布局,定义gridView每个条目的样式。。。
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:paddingBottom="4dip" android:layout_width="fill_parent"> <ImageView android:layout_height="50dip" android:id="@+id/ItemImage" android:layout_width="50dip" android:layout_centerHorizontal="true"> </ImageView> <TextView android:layout_width="wrap_content" android:layout_below="@+id/ItemImage" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:id="@+id/ItemText"> </TextView> </RelativeLayout>
最后整个Activity的代码如下:
package com.wufen;import java.util.List;import android.app.Activity;import android.content.Intent;import android.content.pm.PackageInfo;import android.content.pm.ResolveInfo;import android.os.Bundle;import android.util.Log;import android.view.LayoutInflater;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 MyLauncher extends Activity {private List<ResolveInfo> mApps;GridView myGrid;private List<String> name;private LayoutInflater mInflater;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// setContentView(R.layout.main);loadApps();setContentView(R.layout.main);myGrid = (GridView) findViewById(R.id.apps_list);myGrid.setAdapter(new AppsAdater());}public void loadApps() {Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);mApps = getPackageManager().queryIntentActivities(mainIntent, 0);Log.i("wufen", "" + mApps);}public class AppsAdater extends BaseAdapter {public AppsAdater() {mInflater = LayoutInflater.from(MyLauncher.this);}@Overridepublic int getCount() {// TODO Auto-generated method stubreturn mApps.size();}@Overridepublic Object getItem(int position) {// TODO Auto-generated method stubreturn mApps.get(position);}@Overridepublic long getItemId(int position) {// TODO Auto-generated method stubreturn position;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {ViewHolder holder = null;if (convertView == null) {convertView = mInflater.inflate(R.layout.item, null);holder = new ViewHolder();holder.image = (ImageView) convertView.findViewById(R.id.ItemImage);holder.name = (TextView) convertView.findViewById(R.id.ItemText);convertView.setTag(holder);} else {holder = (ViewHolder) convertView.getTag();}ResolveInfo info = mApps.get(position);holder.image.setImageDrawable(info.activityInfo.loadIcon(getPackageManager()));holder.name.setText(info.activityInfo.loadLabel(getPackageManager()));return convertView;}class ViewHolder {public TextView name;public ImageView image;}}}
效果图:
修改前 修改后
- Android---launcher学习
- android Launcher学习总结
- Android Launcher学习
- android Launcher学习总结
- Android Launcher 学习笔记
- android launcher学习点滴
- Android Launcher开发学习--简易Launcher开发
- android Launcher学习笔记1
- 从Android Launcher源码学习自定义标签
- Android 之launcher学习(one)
- Android之launcher学习(二)
- Android之launcher学习(三)
- Android之launcher学习(四)
- Android学习历程--Launcher拖拽流程
- launcher学习
- Launcher 学习
- launcher 学习
- Android launcher
- File转byte[]
- Css在IE6,IE78和火狐的中的区别
- 黑马程序员-lesson10 jcjq
- Jquery调用Webservice
- UNIX.shell范例精解读书笔记 第一篇
- Android---launcher学习
- 万能视频格式转换器
- 经典数据结构 [ B树,B+树 ]
- FBI树
- eclipse 快捷键
- AFX_MANAGE_STATE(AfxGetStaticModuleState())的一次旅行~
- 为什么Oracle不使用我的索引?
- C++远程调用Call步骤
- UdpClient 与Dispose