Hello Guys 如何在图标下排列 appname ?如果你需要我给出来源。
您可以在此处查看用于创建此视图的代码:
package com.example.draw;
import java.util.List;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class AppInfoAdapter extends BaseAdapter {
private Context mContext;
private List<ApplicationInfo> mListAppInfo;
private PackageManager mPackManager;
public AppInfoAdapter(Context c, List<ApplicationInfo> list, PackageManager pm) {
mContext = c;
mListAppInfo = list;
mPackManager = pm;
}
@Override
public int getCount() {
return mListAppInfo.size();
}
@Override
public Object getItem(int position) {
return mListAppInfo.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// get the selected entry
ApplicationInfo entry = mListAppInfo.get(position);
// reference to convertView
View v = convertView;
// inflate new layout if null
if(v == null) {
LayoutInflater inflater = LayoutInflater.from(mContext);
v = inflater.inflate(R.layout.activity_appinfo, null);
}
// load controls from layout resources
ImageView ivAppIcon = (ImageView)v.findViewById(R.id.ivIcon);
// set data to display
ivAppIcon.setImageDrawable(entry.loadIcon(mPackManager));
// return view
return v;
}
}
文本来自 TextView tvAppName = (TextView)v.findViewById(R.id.tvName); tvAppName.setText(entry.loadLabel(mPackManager));
main_appinfo.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:padding="5dip" >
<ImageView
android:id="@+id/ivIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:contentDescription="@string/desc"
android:scaleType="center"
android:gravity="center_horizontal|center_vertical"/>
</LinearLayout>