在做一个触摸屏测试程序,有个问题想请教下 在屏幕上需要布局好多个相同的方格,点一下方格,颜色就改变了。在xml里面布局那么多view太麻烦了。动态布局不知道怎么去搞 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 直接在view上用canvas画笔画格。点击时动态计算坐标是否点中就行 用gridview写总感觉怪怪的 动态布局很简单,可以尝试一下,下面是我用过的一个动态布局,你可以参考参考SoapObject response = (SoapObject) envelope.getResponse(); Log.e("getResponse","getResponse"); //TODO 填充通知 if(response.getPropertyCount()==0) Toast.makeText(noticeActivity.this, "无系统通知", Toast.LENGTH_SHORT).show(); for(int i=0;i<response.getPropertyCount();i++) { String value=String.valueOf(response.getProperty(i)); String[] values=value.split("__"); TableRow row=new TableRow(this); final TextView textL=new TextView(this); textL.setText(values[0]); textL.setWidth(135); textL.setGravity(Gravity.LEFT); final TextView textC=new TextView(this); textC.setText(values[1]); textC.setWidth(85); textC.setGravity(Gravity.LEFT); final TextView textR=new TextView(this); textR.setText(values[2]); textR.setWidth(100); textR.setGravity(Gravity.RIGHT); row.addView(textL); row.addView(textC); row.addView(textR); final String noticeID=values[3]; if(i%2==0) { row.setBackgroundColor(Color.DKGRAY); } row.setOnClickListener( new TableRow.OnClickListener() { public void onClick(View v) { LayoutInflater layoutInflater = LayoutInflater.from(noticeActivity.this); View noticeView = layoutInflater.inflate(R.layout.notice, null); String noticeContext=getNoticeContextByID(noticeID); TextView noticetxtview = (TextView) noticeView.findViewById(R.id.noticetxt); noticetxtview.setText(noticeContext); new AlertDialog.Builder(noticeActivity.this).setTitle("系统通知").setView( noticeView).setNegativeButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }).show(); } } ); tableLayout.addView(row); } 我刚开始用的grid实现的,后来总觉得很怪,就用的canvas画的,谢谢各位 我的做法:http://blog.csdn.net/sanjinxiong/article/details/7232012 蓝牙问题 升级SDK到R17后ksoap2出问题了 getSystemService无法获取传感器服务,是怎么回事呢? 初学者——求救啊 模拟器启动慢 正在学java,想问java要学到什么程度才能开始学android android里的TimerTask 调查下安卓或Java外包公司,无工作经验,学习6个月,大专一般月薪多少。 Android 进程间通信的争辩 MediaCodec+surfacetexture 播放视频 中途替换surface 如何在TabHost下添加ListView Android多点触屏的问题
用gridview写总感觉怪怪的
Log.e("getResponse","getResponse");
//TODO 填充通知
if(response.getPropertyCount()==0)
Toast.makeText(noticeActivity.this, "无系统通知", Toast.LENGTH_SHORT).show();
for(int i=0;i<response.getPropertyCount();i++)
{
String value=String.valueOf(response.getProperty(i));
String[] values=value.split("__");
TableRow row=new TableRow(this);
final TextView textL=new TextView(this);
textL.setText(values[0]);
textL.setWidth(135);
textL.setGravity(Gravity.LEFT);
final TextView textC=new TextView(this);
textC.setText(values[1]);
textC.setWidth(85);
textC.setGravity(Gravity.LEFT);
final TextView textR=new TextView(this);
textR.setText(values[2]);
textR.setWidth(100);
textR.setGravity(Gravity.RIGHT);
row.addView(textL);
row.addView(textC);
row.addView(textR);
final String noticeID=values[3];
if(i%2==0)
{
row.setBackgroundColor(Color.DKGRAY);
}
row.setOnClickListener(
new TableRow.OnClickListener()
{
public void onClick(View v) {
LayoutInflater layoutInflater = LayoutInflater.from(noticeActivity.this);
View noticeView = layoutInflater.inflate(R.layout.notice, null);
String noticeContext=getNoticeContextByID(noticeID);
TextView noticetxtview = (TextView) noticeView.findViewById(R.id.noticetxt);
noticetxtview.setText(noticeContext);
new AlertDialog.Builder(noticeActivity.this).setTitle("系统通知").setView(
noticeView).setNegativeButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
}).show();
}
}
);
tableLayout.addView(row);
}
http://blog.csdn.net/sanjinxiong/article/details/7232012