Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change absolute position with FrameLayout

I has a View that should be displayed at a specific position over some images, I already did that using AbsoluteLayout, but I don't want to use it and I'm trying to get the same result with a FrameLayout.

But I can't get this working, this is my two attempts:

public void showVideo(RectF bounds) {
    FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) video.getLayoutParams();
    params.width = (int) bounds.width();
    params.height = (int) bounds.height();
    int x = (int) viewer.getPageXOffset();
    int y = (int) viewer.getPageYOffset();

    video.setPadding((int) (x + bounds.left), (int) (y + bounds.top), (int) (x + bounds.right),
            (int) (y + bounds.bottom));

    video.setLayoutParams(params);
    video.invalidate();

    video.setVisibility(View.VISIBLE);
    video.setFocusable(true);
    video.setFocusableInTouchMode(true);
    video.requestFocus();
}

And:

public void showVideo(RectF bounds, final String videoUrl) {
    FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) video.getLayoutParams();
    params.width = (int) bounds.width();
    params.height = (int) bounds.height();
    int x = (int) (viewer.getPageXOffset() + bounds.left);
    int y = (int) (viewer.getPageYOffset() + bounds.top);

    params.leftMargin = x;
    params.topMargin = y;

    video.setLayoutParams(params);
    video.invalidate();

    video.setVisibility(View.VISIBLE);
    video.setFocusable(true);
    video.setFocusableInTouchMode(true);
    video.requestFocus();
}

But in both cases, the VideoView are displayed at v(0,0) (left-top corner).

like image 453
Marcos Vasconcelos Avatar asked Aug 15 '11 17:08

Marcos Vasconcelos


1 Answers

It should work when you set up gravity in LayoutParams.

Try

params.gravity = Gravity.LEFT | Gravity.TOP;

for a start.

like image 71
Digger Avatar answered Nov 13 '22 09:11

Digger