的MediaController定位 - 绑定到VideoView [英] MediaController Positioning - bind to VideoView
问题描述
目前已经有很多关于如何定位讨论的的MediaController
,大部分的答案是使用 setAnchorView
-方法。乍一看这个解决方案似乎工作,但在我的情况并非如此。
There have been a lot of discussions about how to position a MediaController
and most answers are to use the setAnchorView
-Method. At the first glance this solution seems to work but in my case it doesn't.
根据这个邮政 setAnchorView
仅作为参考对于初始定位的的MediaController
,但实际上创建了一个新的浮动窗口
在上面。
According to this Post setAnchorView
only acts as a reference for initial positioning of the MediaController
, but actually creates a new floating Window
on top.
所以,我要的是一个的MediaController
即真正绑定到一个父查看
(如VideoView)。
So what I want is a MediaController
that is really bound to a parent View
(e.g. VideoView).
例如,如果你有一个的LinearLayout
中的滚动型
,你必须向下滚动到你的 VideoView
其中的MediaController
连接到,在的MediaController
应该被附加这个 VideoView
使之与 VideoView
的MediaController 卷轴>。
For example if you have a LinearLayout
within a ScrollView
and you have to scroll down to your VideoView
where the MediaController
is attached to, the MediaController
should really be attached to this VideoView
so that the MediaController
scrolls along with the VideoView
.
另外一个用例在哪里这个问题accurs讨论<一个href=\"http://stackoverflow.com/questions/22564658/mediacontroller-not-swiping-in-viewpager\">here,其中的MediaController
是内部使用的 ViewPager
。
Another Use-Case where this problem accurs is discussed here, where the MediaController
is used within a ViewPager
.
那么如何来实现这样一个行为的MediaController
?
So how to achieve such a behavior for a MediaController
?
推荐答案
最后我做一个肮脏的黑客......我只是手动连接视图,以我的 videoView
实现想要的行为:
I ended up by doing a dirty hack... i just manually attached the view to my videoView
to achieve the wanted behavior:
public void onPrepared(MediaPlayer mp) {
MediaController mc = new MediaController(videoView.getContext(), false);
// set correct height
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) videoView.getLayoutParams();
params.height = mp.getVideoHeight();
videoView.setLayoutParams(params);
videoView.setMediaController(mc);
pBar.setVisibility(View.GONE);
mc.show(0);
FrameLayout f = (FrameLayout) mc.getParent();
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_BOTTOM, videoView.getId());
((LinearLayout) f.getParent()).removeView(f);
((RelativeLayout) videoView.getParent()).addView(f, lp);
mc.setAnchorView(videoView);
}
这个解决方案的问题是,设置anchorView没有任何作用,因此轻敲 VideoView
不隐藏/显示的MediaController
因为它应该。
the problem with this solution is, that setting the anchorView doesn't have any effect and therefore tapping on the VideoView
doesn't hide/show the MediaController
as it's supposed to.
有definitly是一个更好的解决方案,并希望有人能够给我一个提示!
There definitly is a much better solution and hopefully someone can give me a hint!
这篇关于的MediaController定位 - 绑定到VideoView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!