代码如下:
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());
}
}
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());
}
}
解决方案 »
- 第三方jar包 Conversion to Dalvik format failed
- 怎样模拟发送一个触摸屏点击事件给android系统?
- 监听事件中取控件名
- socket在局域网可以通讯,在服务器上不行。
- 程序选择图片返回的时候 程序被杀死重启
- 在网上Download了一个android通讯录,总是出错,请高手指点一下
- 自定义封装layout提示空指针
- ANDROID问题跪求大神解答。。纯新手憋死在这啦。。
- Retrofit上传视频问题
- 菜鸟求大佬大腿安卓网格布局
- android 自带输入法开启与关闭的事件怎么获得
- 如何获取startActivityForResult方法跳转到的子activity的键盘事件
{
case:
}