Android | 等待控件渲染完毕执行操作

王先生
2024-06-26 / 0 评论 / 3 阅读 / 正在检测是否收录...

以 ImageView 控件为例
xml:

            <ImageView
                android:id="@+id/iv_canvas"
                android:background="@color/black"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

java:

    ImageView iv_canvas;

        iv_canvas = findViewById(R.id.iv_canvas);

        iv_canvas.post(()->{
            // 获取当前画布宽高
            double width = iv_canvas.getWidth();
            double height = iv_canvas.getHeight();
            showMsg("当前画布X" + width);
            showMsg("当前画布Y" + height);
        });

评论 (0)

取消