代码如下:
public class AllAppsActivity extends Activity {
    /** Called when the activity is first created. */
private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT;
private final int FP = ViewGroup.LayoutParams.FILL_PARENT;

private LayoutInflater mInflater;
private TableLayout applicationLayout;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        applicationLayout = (TableLayout)findViewById(R.id.applicationLayout);     
        //全部列自动填充空白处
        applicationLayout.setStretchAllColumns(true);
        mInflater = this.getLayoutInflater();//LayoutInflater.from(this);        List<PackageInfo> packageInfos = this.getPackageManager().getInstalledPackages(0);
for (int row = 0; row < (packageInfos.size() / 5 + 1); row++) {
TableRow tableRow = new TableRow(this);
for (int col = 0; col < 5; col++) {
int i = row * 5 + col;
if (i < packageInfos.size()) {
PackageInfo info = packageInfos.get(i);
View view = new View(this);
view = mInflater.inflate(R.layout.application_list, null,false);
TextView name = (TextView) view.findViewById(R.id.name);
ImageView imageView = (ImageView) view
.findViewById(R.id.icon);
name.setText(info.applicationInfo.loadLabel(
this.getPackageManager()).toString());
imageView.setBackgroundDrawable((info.applicationInfo
.loadIcon(this.getPackageManager())));
// applicationLayout.addView();
view.setPadding(0, 15, 0, 0);
view.setTag("colView:"+i);
view.setClickable(true);
view.setFocusable(true);
tableRow.addView(view);
} }
// 新建的TableRow添加到TableLayout
applicationLayout.addView(tableRow, new TableLayout.LayoutParams(FP, WC));
}
applicationLayout.setClickable(true);
applicationLayout.setFocusable(true);
applicationLayout.requestFocus();
View colView = applicationLayout.getFocusedChild();
if(colView!=null)
Log.e("AllAppsActivity", "AllAppsActivity->"+colView.getTag());

    }
}