本文介绍了更改与的FrameLayout绝对位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要超过一些图像的特定位置显示一个视图,我已经做到了使用AbsoluteLayout,但我不希望使用它,我想要得到同样的结果用的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();
}

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();
}

但是,在两种情况下,VideoView显示以v(0,0)(左上角)。

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

推荐答案

当您设置重力的LayoutParams它应该工作。

It should work when you set up gravity in LayoutParams.

尝试

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

有一个开始。

这篇关于更改与的FrameLayout绝对位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-10 20:59