使用FrameLayout更改绝对位置

Mar*_*los 6 android android-layout

我有一个应该显示在某些图像上的特定位置的视图,我已经使用AbsoluteLayout做了,但我不想使用它,我试图用FrameLayout获得相同的结果.

但我不能让这个工作,这是我的两次尝试:

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();
}
Run Code Online (Sandbox Code Playgroud)

和:

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();
}
Run Code Online (Sandbox Code Playgroud)

但在这两种情况下,VideoView都显示在v(0,0)(左上角).

Dig*_*ger 17

它在LayoutParams中设置重力时应该有效.

尝试

params.gravity = Gravity.LEFT | Gravity.TOP;
Run Code Online (Sandbox Code Playgroud)

作为一个开始.