2016-07-27 66 views
1

请帮助我以纵向模式全屏显示视频。我想在应用程序的启动页面全屏显示视频。Android VideoView全屏人像定位

这是我的代码。 我有一个视频视图,它可以填充宽度,但高度只是屏幕中间的一部分。我希望视频视图能够填充整个宽度和高度。

public class SplashFragment extends Fragment { 

public static final String TAG = SplashFragment.class.getSimpleName(); 
private FragmentInterface mFragmentInterface; 
private VideoView mSplashVideoView; 
private Uri mUri; 

public SplashFragment() { 
} 

@Override 
public void onAttach(Context context) { 
    super.onAttach(context); 
    mFragmentInterface = (FragmentInterface) context; 
} 

@Override 
public void onDetach() { 
    super.onDetach(); 
    mFragmentInterface = null; 
} 

@Override 
public void onCreate(@Nullable Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    mFragmentInterface.showActionBar(false); 
} 

@Nullable 
@Override 
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout.fragment_splash, container, false); 
    return view; 
} 

@Override 
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 
    super.onViewCreated(view, savedInstanceState); 
    initView(view); 
    initListener(); 
    playVideo(); 
} 

@Override 
public void onResume() { 
    super.onResume(); 
    playVideo(); 
} 

private void initView(View view) { 
    mSplashVideoView = (VideoView) view.findViewById(R.id.splashVideoView); 
    mUri = Uri.parse("android.resource://" + getActivity().getApplication().getPackageName() + "/" + R.raw.mylawmp4); 
    mSplashVideoView.setMediaController(null); 
    mSplashVideoView.setVideoURI(mUri); 
} 

private void initListener() { 
    mSplashVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 
     @Override 
     public void onCompletion(MediaPlayer mp) { 
      displayScreens(); 
     } 
    }); 
} 

private void playVideo() { 
    mSplashVideoView.setZOrderOnTop(true); 
    mSplashVideoView.start(); 
} 

private void displayScreens() { 
    if (mFragmentInterface != null) { 
     if (!PreferenceUtil.isLoggedIn(getActivity())) { 
      mFragmentInterface.action(Constants.FragmentInterfaceConstants.ACTION_SEND_OTP, null); 
     } else { 
      mFragmentInterface.action(Constants.FragmentInterfaceConstants.ACTION_HOME, null); 
     } 
    } 
} 

}

XML布局看起来像下面

<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/splashScreen" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <VideoView 
     android:id="@+id/splashVideoView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     android:visibility="visible" /> </FrameLayout> 
+0

试试这个: '机器人:layout_gravity = “CENTER_HORIZONTAL | center_vertical”' –

回答

2

尝试在你的XML布局添加以下属性您VideoView

<VideoView 
    android:id="@+id/splashVideoView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentTop="true"/> 
+0

感谢工作reply..its .. –

+0

您的欢迎@Lincy Laiju – Arshak

+0

嘿,我有一个疑问...视频似乎被拉长了。我们可以做些什么,或者我应该要求设计团队提供不同比例的视频以适应不同的屏幕。 –

0

好吧,我想你必须编辑你的清单文件并在其中添加一些代码:

“我希望这个作品”

+0

感谢您的回复..我试了一下。只有上面的代码不会给结果... –