Scrollview中的重量

时间:2014-01-13 21:16:27

标签: android scrollview

我在Android应用上的滚动视图中计算weight时遇到问题。我希望应用的内容与屏幕大小成比例调整大小。如何计算滚动视图中的weight

这是我的一些代码:

  LinearLayout layout_principal = (LinearLayout) findViewById(R.id.layout_items);// is horizontal layout and layout of Scrollview

  LinearLayout layout_titulo_opcion = new LinearLayout(this);
  LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
          LinearLayout.LayoutParams.FILL_PARENT,
          0,
          1f);
  layout_titulo_opcion.setLayoutParams(layoutParams);

  LinearLayout layout_titulo_opcion2 = new LinearLayout(this);
  LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(
          LinearLayout.LayoutParams.FILL_PARENT,
          0,
          1f);
  layout_titulo_opcion2.setLayoutParams(layoutParams2);

  layout_principal.addView(layout_titulo_opcion);
  layout_principal.addView(layout_titulo_opcion2);

1 个答案:

答案 0 :(得分:0)

要获得/设定体重,请使用:

LinearLayout.LayoutParams mylp = (LinearLayout.LayoutParams)myLayout.getLayoutParams();
int myWeight = mylp.weight; // get weight
mylp.weight = 4; // set weight

要设置权重总和,请使用:

myLayout.setWeightSum(10);