2012-09-18 139 views
0

我有一個視頻視圖。當我觸摸它時,它應該顯示在幾乎全屏視圖的對話框中。對於我用下面的代碼:如何在對話框中全屏顯示視頻視圖?

mVideoFirst.setOnTouchListener(new OnTouchListener() { 
        @Override 
        public boolean onTouch(View v, MotionEvent event) { 
         mVideoFirst.stopPlayback(); 
         mVideoDialog.show(); 
         mVideoFullScreen.setVideoPath(clip1.getAbsolutePath()); 
         mMediaController3.setMediaPlayer(mVideoFullScreen); 
         mVideoFullScreen.setMediaController(mMediaController3); 
         mVideoFullScreen.requestFocus(); 
         mVideoFullScreen.start(); 
         return false; 
        } 
       }); 

對於我用下面的java代碼的對話框:

mVideoDialog = new Dialog(this); 
    mVideoDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    mVideoDialog.setContentView(R.layout.fullscreen_video); 
    mVideoDialog.setOnKeyListener(this); 
    mVideoFullScreen = (VideoView) mVideoDialog.findViewById(R.id.fullscreen_videoview); 

這裏是我的XML卑鄙的對話框:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <VideoView 
     android:id="@+id/fullscreen_videoview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" > 
    </VideoView> 

</RelativeLayout> 

現在問題是,視頻在對話框中播放。但視頻進入對話框的右側。對話框左側有很多空白區域。控制器隱藏在對話框後面。所以我無法使用視頻控制器控制視頻,因爲我無法觸摸它。

任何一個可以幫助我..

回答

0

我想mVideoDialog.setContentView(R.layout.fullscreen_video);之前,你應該叫mVideoDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)使對話框全屏。

+0

這樣我tried..but仍然有一些30像素的保證金.. –

+1

以及視頻控制器警報dialog..how後面來克服這個問題?? –

+0

檢查我對這個問題的回答,以解決視頻控制器背後的對話框。 http://stackoverflow.com/a/25227176/2693789 –

0

您需要將佈局和視頻視圖高度和寬度設置爲匹配父級。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<VideoView 
    android:id="@+id/fullscreen_videoview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" > 
</VideoView> 
+0

它仍然沒有來到整個屏幕.. –

0

您可以作出這樣的自定義視頻控件:

public class FullScreenVideoView extends VideoView { 
 
    public FullScreenVideoView(Context context) { 
 
     super(context); 
 
    } 
 

 
    public FullScreenVideoView(Context context, AttributeSet attrs) { 
 
     super(context, attrs); 
 
    } 
 

 
    public FullScreenVideoView(Context context, AttributeSet attrs, int defStyle) { 
 
     super(context, attrs, defStyle); 
 
    } 
 

 
    @Override 
 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){ 
 
     super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
 
     setMeasuredDimension(widthMeasureSpec, heightMeasureSpec); 
 
    } 
 
}

,並在你的XML使用控制:

<com.yourpackagename.FullScreenVideoView 
 
       android:id="@+id/videoView" 
 
       android:layout_width="fill_parent" 
 
       android:layout_height="fill_parent" />

對話窗口:

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); 
 
     LayoutInflater inflater = getLayoutInflater(); 
 
     View dialogView = inflater.inflate(R.layout.your_custom_dialog_xml, null); 
 
     dialogBuilder.setView(dialogView); 
 
     final Dialog dialog = dialogBuilder.create(); 
 
     dialog.setCancelable(false); 
 
     dialog.show();