开发者

Android postioning of a view

开发者 https://www.devze.com 2023-02-17 11:06 出处:网络
I have created CustomView. The view is higher in size than the screen. So it is showing fully in the device s开发者_开发问答creen.

I have created CustomView. The view is higher in size than the screen. So it is showing fully in the device s开发者_开发问答creen.

I want to determine position to determine how much it is outside the screen in left, right top and bottom. How to do that?


For what purpose you want to know how much of your view is outside of the screen? Can't you just use Scroller?


You can call getLocalVisibleRect on the view to get the "on screen" rectangle.

For example say in your onDraw

@Override
protected void onDraw(Canvas canvas) {
    Rect r=new Rect();
    getLocalVisibleRect(r);
    // 0 to r.top is above the visible screen, etc
    ...

Once you have that rect it should be simple to calculate the values you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消