用OnLayoutChangeListener的方法解决getTop=0的问题

 private val mLayoutChangeListener: View.OnLayoutChangeListener by lazy {
        View.OnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
            checkPosition()
            mLayout.postDelayed({
            	//接触监听
                mLayoutt.removeOnLayoutChangeListener(mLayoutChangeListener)
            }, 500)
        }
    }

override fun initView(rootView: View) {
	//添加监听
	mLayout.addOnLayoutChangeListener(mLayoutChangeListener)
}

private fun checkPosition(){
        val aViewY = mAView.top
        val bViewtY = mBView.top + mBView.measuredHeight
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用所提供的内容,下面是用C语言编写的栈解决迷宫问题的代码: ```c #include <stdio.h> #define MAXSIZE 100 typedef struct { int row; int col; } Position; typedef struct { Position data[MAXSIZE]; int top; } Stack; void initStack(Stack *s) { s->top = -1; } void push(Stack *s, Position p) { if (s->top == MAXSIZE - 1) { printf("Stack is full.\n"); return; } s->top++; s->data[s->top] = p; } void pop(Stack *s) { if (s->top == -1) { printf("Stack is empty.\n"); return; } s->top--; } int isEmpty(Stack s) { return s.top == -1; } Position getTop(Stack s) { return s.data[s.top]; } int main() { int mg[5][5] = {{0, 1, 0, 0, 0}, {0, 1, 0, 1, 0}, {0, 0, 0, 0, 0}, {0, 1, 1, 1, 0}, {0, 0, 0, 1, 0}}; Stack s; initStack(&s); Position start = {0, 0}; push(&s, start); mg[start.row][start.col] = -1; while (!isEmpty(s)) { Position curPos = getTop(s); if (curPos.row == 4 && curPos.col == 4) { printf("Find the path!\n"); break; } int i, newRow, newCol; for (i = 0; i < 4; i++) { switch (i) { case 0: newRow = curPos.row - 1; newCol = curPos.col; break; case 1: newRow = curPos.row; newCol = curPos.col + 1; break; case 2: newRow = curPos.row + 1; newCol = curPos.col; break; case 3: newRow = curPos.row; newCol = curPos.col - 1; break; } if (newRow >= 0 && newRow < 5 && newCol >= 0 && newCol < 5 && mg[newRow][newCol] == 0) { Position newPos = {newRow, newCol}; push(&s, newPos); mg[newRow][newCol] = -1; break; } } if (i == 4) { pop(&s); } } if (isEmpty(s)) { printf("No path found.\n"); } return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值