如何获取活动中包含的VideoView的高度 [英] How to get the Height of the VideoView included in the Activity
本文介绍了如何获取活动中包含的VideoView的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要获取我在android中活动的VideoView的高度,我正在使用以下命令,但它的高度为0.
I need to get the Height of the VideoView of my activity in android, I am using the following commands, but it gives me the Height as 0.
VideoView vv = (VideoView)findViewById(R.id.video1);
String surl="SOME_LINK.mp4";
Uri uri=Uri.parse(surl);
MediaController mc = new MediaController(this);
vv.setVideoURI(uri);
vv.setMediaController(mc);
mc.setMediaPlayer(vv);
mc.setAnchorView(vv);
int vvHeight=vv.getMeasuredHeight();
Log.d("VideoView Height:",vvHeight+""); // The Logcat output : 0.
int VVheight=vv.getHeight();
Log.d("The Height of VideoView is :",VVheight+""); // The Logcat output : 0
有人可以告诉我我犯了什么错误吗?
Can Someone tell me what I am making an mistake.
推荐答案
您正在尝试在绘制视图之前获取宽度/高度.
You are trying to get width/height before the view has been drawn.
尝试一下:
vv.post(new Runnable() {
@Override
public void run() {
// get height and width here
}
});
view.post(Runnable)
导致将可运行对象添加到消息队列中.可运行对象将在UI线程上运行.
view.post(Runnable)
causes the runnable to be added to the message queue. The runnable will run on the UI thread.
这篇关于如何获取活动中包含的VideoView的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文