在ngui scrollview里动态添加个textView是怎么做到的?想必许多朋友和我一样开始的时候有点困惑,今天我们就来看看在ngui scrollview里怎么动态添加个textView。
这是oneTab的java代码:用来加载tab的内容页面的
这是oneTab的java代码:用来加载tab的内容页面的
- public class OneTab extends Activity implements OnTouchListener {
- /** Called when the activity is first created. */
- int count=0;
- long firClick;
- long secClick;
- TextView textView;
- private LinearLayout mLayout;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.onetabgridview);
- mLayout=(LinearLayout)findViewById(R.id.layout);
- // 取得GridView对象
- GridView gridview = (GridView) findViewById(R.id.gridview);
- gridview.setFocusableInTouchMode(true);
- // 添加元素给gridview
- gridview.setAdapter(new ImageAdapter(this));
- // 设置gridview的背景
- gridview.setBackgroundResource(R.drawable.bg);
- //gridView双击事件
- gridview.setOnTouchListener(this);
- }
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- //双击事件
- if(MotionEvent.ACTION_DOWN == event.getAction()){
- count++;
- if(count == 1){
- firClick = System.currentTimeMillis();
- } else if (count == 2){
- secClick = System.currentTimeMillis();
- if(secClick - firClick < 1000){
- textView=new TextView(this);
- textView.setText("aaaaaaaaaaaaa");
- //双击事件,动态给scroolView增加控件
- //设置线性布局的属性
- LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.FILL_PARENT,
- LinearLayout.LayoutParams.WRAP_CONTENT);
- mLayout.addView(textView,params);
- }
- count = 0;
- firClick =0;
- secClick =0;
- }
- }
- return true;
- }
- }