2011-10-21 103 views
1

我已經創建了以下layout.which具有兩個相對佈局和一個滾動視圖,下面的代碼包含佈局的標題。我需要創建工作表,我將使用循環。將滾動視圖添加到使用java代碼的佈局

RelativeLayout inner=new RelativeLayout(this); 
    inner.setBackgroundColor(Color.RED); 
    outerLayout=new RelativeLayout(this); 
    ScrollView scroll=new ScrollView(this); 
    TextView qty=new TextView(this); 
    qty.setId(1111); 
    inner.addView(qty); 
    qty.setTextColor(Color.WHITE); 
    qty.setText("Qty"); 

    setContentView(outerLayout); 
    RelativeLayout.LayoutParams p=new   RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,30); 
    p.addRule(RelativeLayout.RIGHT_OF,qty.getId()) 

    ; 
    p.leftMargin=30; 

    TextView partNo=new TextView(this); 
    partNo.setText("Part no"); 
    partNo.setId(2222); 
    partNo.setLayoutParams(p); 
    partNo.setTextColor(Color.WHITE); 


    inner.addView(partNo); 

    RelativeLayout.LayoutParams descLayout=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,30); 
    descLayout.addRule(RelativeLayout.RIGHT_OF,partNo.getId()) 

    ; 
    descLayout.leftMargin=30; 

    TextView desc=new TextView(this); 
    desc.setText("Description"); 
    desc.setId(3333); 
    desc.setLayoutParams(descLayout); 
    desc.setTextColor(Color.WHITE); 


    inner.addView(desc); 


    RelativeLayout.LayoutParams commentLayout=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,30); 
    commentLayout.addRule(RelativeLayout.RIGHT_OF,desc.getId()) 

    ; 
    commentLayout.leftMargin=30; 

    TextView comment=new TextView(this); 
    comment.setText("Comments"); 
    comment.setId(4444); 
    comment.setLayoutParams(commentLayout); 
    comment.setTextColor(Color.WHITE); 


    inner.addView(comment); 


    RelativeLayout.LayoutParams retailLayout=new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,50); 
    retailLayout.addRule(RelativeLayout.RIGHT_OF,comment.getId()) 

    ; 
    retailLayout.leftMargin=30; 

    TextView retail=new TextView(this); 
    retail.setText("Retail \n Reference"); 
    retail.setId(5555); 
    retail.setLayoutParams(retailLayout); 
    retail.setTextColor(Color.WHITE); 


    inner.addView(retail); 
    scroll.setVerticalScrollBarEnabled(true); 
    scroll.setHorizontalScrollBarEnabled(true); 


    scroll.addView(inner); 

    outerLayout.addView(scroll); 

我試圖滾動視圖添加到佈局,但不幸的是我無法看到滾動視圖。請幫助,我怎樣才能滾動視圖添加到上面的佈局。

回答

0

不知道是否它的問題,但我沒有看到你在ScrollView上設置佈局參數。

+0

這PARAMS我需要設置請解釋 – androider

+0

你將它添加到的RelativeLayout所以像: RelativeLayout.LayoutParams P =新RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT); scroll.setLayoutParams(p); – Joe

相關問題