請幫助我以縱向模式全屏顯示視頻。我想在應用程序的啓動頁面全屏顯示視頻。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>
試試這個: '機器人:layout_gravity = 「CENTER_HORIZONTAL | center_vertical」' –