android中, 如何让布局文件中定义的一个Layout接收点击事件,并为它添加Listener。或者是类似的功能实现
展开全部
LinearLayout layout=new LinearLayout(this);
layout.setBackgroundColor(Color.GREEN);
LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(200, 50);
ImageView imageView=new ImageView(this);
imageView.setImageResource(R.drawable.icon);
layout.addView(imageView, params);
setContentView(layout);
layout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("tag", "点击了layout!! ");
}
});
}
layout.setBackgroundColor(Color.GREEN);
LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(200, 50);
ImageView imageView=new ImageView(this);
imageView.setImageResource(R.drawable.icon);
layout.addView(imageView, params);
setContentView(layout);
layout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("tag", "点击了layout!! ");
}
});
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询