Code example for HorizontalScrollView

Methods: addView

0
		if (rows < 1) numRows = 1;
		else if (rows > 3) numRows = 3;
		else numRows = rows;
		 
		//	set up mainLayout and rowContainer which will contain all elements 
    	scrollLayout = new HorizontalScrollView(context);
    	 
    	rowContainer = new LinearLayout(context);
    	rowContainer.setOrientation(LinearLayout.VERTICAL);
    	LinearLayout.LayoutParams subParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
    	 
    	//	set up each row individually 
    	row1 = new LinearLayout(context);
    	LinearLayout.LayoutParams row1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, CARD_PIC_HEIGHT);
    	row1Params.setMargins(0, SPACER_HEIGHT, 0, SPACER_HEIGHT);
    	rowContainer.addView(row1, row1Params);
    	row1.addView(new View(context), new ViewGroup.LayoutParams(SPACER_WIDTH, SPACER_HEIGHT));
    	 
    	if (numRows >= 2) {
    		row2 = new LinearLayout(context);
    		LinearLayout.LayoutParams row2Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, CARD_PIC_HEIGHT);
        	row2Params.setMargins(0, 0, 0, SPACER_HEIGHT);
        	rowContainer.addView(row2, row2Params);
        	row2.addView(new View(context), new ViewGroup.LayoutParams(SPACER_WIDTH, SPACER_HEIGHT));
    	} 
    	if (numRows >= 3) {
    		row3 = new LinearLayout(context);
    		LinearLayout.LayoutParams row3Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, CARD_PIC_HEIGHT);
        	row3Params.setMargins(0, 0, 0, SPACER_HEIGHT);
        	rowContainer.addView(row3, row3Params);
        	row3.addView(new View(context), new ViewGroup.LayoutParams(SPACER_WIDTH, SPACER_HEIGHT));
    	} 
    	 
    	scrollLayout.addView(rowContainer, subParams);
	} 
	 
	public void addCard(String entry) {
		//	create the new button 
		Button cardButton = new Button(context);