在做一个触摸屏测试程序,有个问题想请教下

2在路上 2012-02-01 05:58:19
在屏幕上需要布局好多个相同的方格,点一下方格,颜色就改变了。在xml里面布局那么多view太麻烦了。动态布局不知道怎么去搞
...全文
121 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
2在路上 2012-02-03
  • 打赏
  • 举报
回复
我的做法:
http://blog.csdn.net/sanjinxiong/article/details/7232012
2在路上 2012-02-03
  • 打赏
  • 举报
回复
我刚开始用的grid实现的,后来总觉得很怪,就用的canvas画的,谢谢各位
LichKingSZ 2012-02-02
  • 打赏
  • 举报
回复
2楼的方法扩展性更好
MistX 2012-02-02
  • 打赏
  • 举报
回复
动态布局很简单,可以尝试一下,下面是我用过的一个动态布局,你可以参考参考

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);
}
2在路上 2012-02-02
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 sinom 的回复:]

2楼的方法扩展性更好
[/Quote]

用gridview写总感觉怪怪的
傲慢的上校 2012-02-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jacygmail 的回复:]
gridview
[/Quote]gridview
danielinbiti 2012-02-01
  • 打赏
  • 举报
回复
直接在view上用canvas画笔画格。点击时动态计算坐标是否点中就行
jacyGmail 2012-02-01
  • 打赏
  • 举报
回复
gridview

80,350

社区成员

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

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