gpt4 book ai didi

android - 如何以编程方式修改videoview的宽度

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:02:53 27 4
gpt4 key购买 nike

我在我的 Activity 中创建了一个视频 View ,当 Activity 开始时,我想修改视频的高度和宽度。怎么做?

这是我的代码。我尝试了简单的布局参数和框架布局,但对我没有任何作用

            final VideoView vvVideos = (VideoView) rootView.findViewById(R.id.videoView);
MediaController mediacontroller = new MediaController(ctx);
mediacontroller.setAnchorView(vvVideos);
String videoFileName = videos.get(position);
Uri video = Uri.parse("android.resource://" + packageName +"/"+R.raw.sample);
vvVideos.setMediaController(mediacontroller);
//LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,150);
vvVideos.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,150));
vvVideos.setVideoURI(video);
vvVideos.requestFocus();
vvVideos.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
//pDialog.dismiss();
vvVideos.start();
}
});

解决方案

这段代码对我有用....

            LayoutParams params=vvVideos.getLayoutParams();
params.height=150;
vvVideos.setLayoutParams(params);

最佳答案

试试这个,对我有用

VideoView video=(VideoView) findViewById(R.id.videoView1);
video.setVideoURI(setVideoUri());
video.setVisibility(View.VISIBLE);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)video.getLayoutParams();
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, 0);
video.setLayoutParams(layoutParams);

关于android - 如何以编程方式修改videoview的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17063671/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com