9

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

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

            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);
4

2 回答 2

4

试试这个,它对我有用

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);
于 2013-06-12T11:03:56.770 回答
0
VideoView videoview=(VideoView) findViewById(R.id.videoView1);
videoview.setVideoURI("yourURI");
videoview.setLayoutParams(new FrameLayout.LayoutParams(550,550));

LinearLayout linearLayout = (LinearLayout)findViewById(R.id.info)
linearLayout.addView(videoview);
于 2013-06-12T11:10:16.173 回答