请教:TableLayout中入的View怎样才能获得焦点

hanfengthinker 2010-12-22 08:02:48
如题:TableLayout中加了一此ImageView/TextView后想让可获得焦点并可正常的上下左右移动
...全文
273 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hanfengthinker 2010-12-27
  • 打赏
  • 举报
回复
最后还是用了GridView来实现了……还是谢谢
Dartagnan 2010-12-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 programmerno1 的回复:]

获得焦点有现成方法

上下左右移动根据消息机制实现

switch()
{
case:
}
[/Quote]

顶!
ProgrammerNO1 2010-12-22
  • 打赏
  • 举报
回复
获得焦点有现成方法

上下左右移动根据消息机制实现

switch()
{
case:
}
hanfengthinker 2010-12-22
  • 打赏
  • 举报
回复
代码如下:


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());

}
}

80,472

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧