framelayout中的中心播放按钮在videoview上以编程方式安卓

时间:2013-12-06 15:02:53

标签: android center android-videoview android-framelayout

我想在这个videoview上专门设置视频和播放按钮

要做到这一点,我已经创建了一个framelayout,其中我放了两个

这是代码:

FrameLayout frm_video = new FrameLayout(this);                                      

                FrameLayout.LayoutParams params_frm_video = new FrameLayout.LayoutParams(
                        150,90);
                params_frm_video.gravity = Gravity.CENTER;
                frm_video.setLayoutParams(params_frm_video);                                        


                MediaMetadataRetriever retriever = new MediaMetadataRetriever();
                retriever.setDataSource(f.getFile().getPath());

                Bitmap b = retriever.getFrameAtTime();

                BitmapDrawable b1 = new BitmapDrawable(
                        getResources(), b);                                                             

                RelativeLayout.LayoutParams layoutParams = 
                        new RelativeLayout.LayoutParams(50,50);
                    layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);

                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                        150,90);
                params.gravity = Gravity.CENTER;

                VideoView overview_video = new VideoView(this);                 
                overview_video.setBackground(b1);                                   

                frm_video.addView(overview_video);

                ImageButton play_btn = new ImageButton(this);
                play_btn.setBackgroundResource(R.drawable.btn_play);

                play_btn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        seeItem(liste.get(v.getId()-1300));

                    }
                });     

                LinearLayout.LayoutParams params_play_btn = new LinearLayout.LayoutParams(
                        50,50);
                params_play_btn.gravity = Gravity.CENTER;
                play_btn.setLayoutParams(params_play_btn);
                frm_video.addView(play_btn);
                play_btn.setId(1300+i);

                item_layout.addView(frm_video,params_frm_video);

我希望播放按钮位于framelayout和videoview的中心 但我不能那样做

然后我设法用xml做了,但是programmaticaly播放按钮位于framelayout的左上角

以下是此代码的捕获:

enter image description here

如何解决此问题

2 个答案:

答案 0 :(得分:0)

我找到解决方案, 我必须使用:

FrameLayout.LayoutParams params_play_btn = new FrameLayout.LayoutParams(
                        50,50);

作为layoutparams,因为我正在使用FrameLayout 而不是

LinearLayout.LayoutParams

我希望它有所帮助

答案 1 :(得分:-1)

这不是programmaticaly,但你可以设置

 android:layout_centerHorizontal="true" 
 android:layout_centerVertical="true"