通过android Studio中的代码更改图像按钮的高度

时间:2015-07-09 10:15:54

标签: android

我在Android工作室工作并使用TableLayout。我想显示小图像按钮。每个按钮的高度可以通过编程方式更改。我已经尽力了。但是不会改变imageButton的高度,请任何人帮助我,我可以在此代码中做出哪些更改。感谢

 public void settable() {
        index = 0;

        LinearLayout le = (LinearLayout) findViewById(R.id.onofffbutton);
        float height = le.getHeight();
        height= height/9.0f;

        for (int a = 0; a < maxrow; a++) {
            TableRow row = new TableRow(this);

            for (int b = 0; b < col; b++) {
                location[a][b] = new ImageView(this);
                /*LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(50, 50);
                location[a][b].setLayoutParams(layoutParams);*/
                if (isOn[a][b]) {
                    location[a][b].setBackgroundResource(R.drawable.box1);
                } else {
                    location[a][b].setBackgroundResource(R.drawable.box);
                }
                location[a][b].setMaxHeight(height);

                location[a][b].setOnClickListener(Onclick);
                location[a][b].setId(index++);
                row.addView(location[a][b]);
            }
            tableLayout.addView(row, a);
        }
    }

0 个答案:

没有答案