【发布时间】:2014-01-23 08:35:40
【问题描述】:
我正在尝试在 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() 中找到的循环中,我遍历ArrayList 中的所有元素,每个元素都有一个percentage 变量。这是我想乘以高度的变量。
我试图将在initChart 中找到的膨胀的RelativeLayout 的LayoutParams 的高度相乘,但是由于在onCreate() 中调用它,它的高度属性不正确。
那么我怎样才能确保我添加到我的 View 的膨胀的 RelativeLayout 的高度与从 c(c.getPercentage()) 获得的百分比相对应
【问题讨论】:
标签: android android-layout horizontalscrollview oncreate