ngui scrollview里动态添加个textView是怎么做到的?想必许多朋友和我一样开始的时候有点困惑,今天我们就来看看在ngui scrollview里怎么动态添加个textView。
这是oneTab的java代码:用来加载tab的内容页面的
  1. public class OneTab extends Activity implements OnTouchListener {
  2. /** Called when the activity is first created. */
  3. int count=0;
  4. long firClick;
  5. long secClick;
  6. TextView textView;
  7. private LinearLayout mLayout;
  8. @Override
  9. public void onCreate(Bundle savedInstanceState) {
  10. super.onCreate(savedInstanceState);
  11. setContentView(R.layout.onetabgridview);
  12. mLayout=(LinearLayout)findViewById(R.id.layout);
  13. // 取得GridView对象
  14. GridView gridview = (GridView) findViewById(R.id.gridview);
  15. gridview.setFocusableInTouchMode(true);
  16. // 添加元素给gridview
  17. gridview.setAdapter(new ImageAdapter(this));
  18. // 设置gridview的背景
  19. gridview.setBackgroundResource(R.drawable.bg);
  20. //gridView双击事件
  21. gridview.setOnTouchListener(this);
  22. }
  23. @Override
  24. public boolean onTouch(View v, MotionEvent event) {
  25. //双击事件
  26. if(MotionEvent.ACTION_DOWN == event.getAction()){
  27. count++;
  28. if(count == 1){
  29. firClick = System.currentTimeMillis();
  30. } else if (count == 2){
  31. secClick = System.currentTimeMillis();
  32. if(secClick - firClick < 1000){
  33. textView=new TextView(this);
  34. textView.setText("aaaaaaaaaaaaa");
  35. //双击事件,动态给scroolView增加控件
  36. //设置线性布局的属性
  37. LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(
  38. LinearLayout.LayoutParams.FILL_PARENT,
  39. LinearLayout.LayoutParams.WRAP_CONTENT);
  40. mLayout.addView(textView,params);
  41. }
  42. count = 0;
  43. firClick =0;
  44. secClick =0;
  45. }
  46. }
  47. return true;
  48. }
  49. }