Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 测量“确定”按钮时仅查看组布局问题_Android_Keyboard_Viewgroup - Fatal编程技术网

Android 测量“确定”按钮时仅查看组布局问题

Android 测量“确定”按钮时仅查看组布局问题,android,keyboard,viewgroup,Android,Keyboard,Viewgroup,我从扩展视图组创建了键盘。我对onLayout()方法有问题。我想将确定按钮从一个方块更改为三个方块。怎么做 public class KeyboardVolume extends ViewGroup { @Override protected void onLayout(boolean c, int l, int t, int r, int b) { int height = b - t; // view height = view bot

我从扩展视图组创建了键盘。我对onLayout()方法有问题。我想将确定按钮一个方块更改为三个方块。怎么做

public class KeyboardVolume extends ViewGroup {

    @Override
    protected void onLayout(boolean c, int l, int t, int r, int b) {
        int height = b - t;           // view height = view bottom - view top
        int width = r - l;            // view width = view right - view left
        int rows = 4;                 // rows count (4 keys)
        int colums = 4;               // columns count (4 keys)
        int gridW = (width / colums); // key width
        int gridH = (height / rows);  // key height
        int left;
        int top = 1;
        int count = 0;

        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < colums; j++) {
                count++;
                int id = (i * colums) + j;
                View child = this.getChildAt(id);
                if (child == null) {
                    return;
                }
                left = j * (gridW + 1);
                if (gridW != child.getMeasuredWidth() || gridH != child.getMeasuredHeight()) {
                    child.measure(makeMeasureSpec(gridW, EXACTLY), makeMeasureSpec(gridH, EXACTLY));
                }
                if (count < (rows * colums)) {
                    child.layout(left, top, left + gridW, top + gridH);
                } else {
                    left -= 1;
                    top -= 1;
                    child.layout(left, top, left + gridW, top + gridH);
                }
            }
            top += gridH + 1;
        }
    }

}
公共类键盘卷扩展了视图组{
@凌驾
仅受保护的void布局(布尔c、int l、int t、int r、int b){
int height=b-t;//视图高度=视图底部-视图顶部
int width=r-l;//视图宽度=视图右-视图左
int rows=4;//行数(4个键)
int columns=4;//列计数(4个键)
int gridW=(宽度/列);//键宽度
int gridH=(高度/行);//键高度
int左;
int-top=1;
整数计数=0;
对于(int i=0;i
以上代码的输出是

预期产量为