2014-01-23 14 views
1

我想在android中創建一個條形圖,其中每個條形包含一個View和一個TextView。 我將這些細胞添加到HorizontalScrollView。這工作正常,所有我的酒吧出現。通過乘以一個因子來調整條形圖中元素的大小

現在我想調整這些小節的大小(因爲它們現在全部出現在全高度),方法是將它們乘以一個因子。

這是我使用的活動類。

private ViewGroup linearScrollLayout; 
private HorizontalScrollView hScrollView; 
private ArrayList<NutrientCell> nutrientsData; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.box_plot); 
    this.hScrollView = (HorizontalScrollView) findViewById(R.id.horizontalScrollView1); 
    this.linearScrollLayout = (ViewGroup) this.hScrollView 
      .findViewById(R.id.linearScrollLayout); 

    try { 
     Intent intent = getIntent(); 
     this.nutrientsData = (ArrayList<NutrientCell>) intent 
       .getSerializableExtra("nutrientsData"); 
     // 
    } catch (Exception e) { 
     // TODO: handle exception 
    } 
    this.initChart(); 
} 

private void initChart() { 

    for (NutrientCell c : this.nutrientsData) { 

     RelativeLayout rlt = (RelativeLayout) getLayoutInflater().inflate(
       R.layout.hv_boxplot_cell, this.linearScrollLayout, false); 

     ((TextView) rlt.findViewById(R.id.textView1)).setText(c 
       .getNutrientName().toString()); 

     View v = ((View) rlt.findViewById(R.id.vv1)); 
     v.setBackgroundColor(c.getColor()); 

     this.linearScrollLayout.addView(rlt); 
    } 

} 

現在,在initChart()發現環路I遍歷在ArrayList所有元素,其中的每一個具有一percentage變量。這是我想用高度乘以的變量。 我試過只乘以initChart中找到的膨脹的RelativeLayout的LayoutParams的高度,但是因爲這是在onCreate()中調用的,所以它的高度屬性不正確。

所以,我怎麼能確保膨脹的RelativeLayout我添加到我的觀點已經相當於

回答

0

究竟是用來做什麼的比例從cc.getPercentage())獲得的百分比的高度?如果百分比用於根據初始大小縮放視圖,則可以使用視圖的setScaleY()方法更改其高度。

相關問題