dynamic create layout

LinearLayout containerLayout = (LinearLayout)findViewById(R.id.scrollviewlayout);
		
		containerScrollView = new ScrollView(this);
		//set scrollview layout
		containerScrollView.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		

		//disable the stupid scrollview from jumping the edittext focus
		
		containerScrollView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
		//containerScrollView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
		containerScrollView.setFocusable(true);
		containerScrollView.setFocusableInTouchMode(true);
		containerScrollView.setOnTouchListener(new OnTouchListener() {
			
			public boolean onTouch(View v, MotionEvent event) {
				v.requestFocusFromTouch();
				return false;
			}
		});

contentLinearLayout = new LinearLayout(this);
		contentLinearLayout.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
		contentLinearLayout.setOrientation(LinearLayout.VERTICAL);
		
		containerScrollView.addView(contentLinearLayout);		
		
        containerLayout.addView(containerScrollView);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章