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).
It should work when you set up gravity in LayoutParams.
Try
params.gravity = Gravity.LEFT | Gravity.TOP;
for a start.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With