view.getTop()给我错误的坐标

时间:2014-02-23 18:37:37

标签: android canvas android-view

我有一个带有linearLayout的xml,它不能覆盖整个屏幕 我在mainActivity中控制了它并将其发送到另一个类:

        GameView gv;
        setContentView(R.layout.game_view);
        LinearLayout surface = new LinearLayout(this);
        surface = (LinearLayout)findViewById(R.id.surface);
        gv= new GameView(this,surface);
        surface.addView(gv);

在GameView类中我得到了上下文和linearlayout:

public GameView(Context context,LinearLayout view)

然后我使用函数getLeft()getTop()getRight()getBottom()layout

上画一个大的矩形
        Paint p=new Paint();
        p.setColor(Color.BLACK);
        canvas.drawColor(Color.BLUE);
        canvas.drawRect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom(),p);

getLeft()getRight()工作正常,但getTop()getBottom()偏移约6 pxs;

我不知道为什么会发生这种情况

0 个答案:

没有答案
相关问题