2016-07-27 15 views
1

Bitte helfen Sie mir mit Video-Ansicht Vollbild im Hochformat.Ich möchte ein Video im Vollbild auf der Splash-Seite für eine App anzeigen.Android VideoView Vollbild im Hochformat

Dies ist mein Code. Ich habe eine Videoansicht, die die Breite füllt, aber die Höhe ist nur ein Teil des Bildschirms in der Mitte. Ich möchte die Videoansicht die gesamte Breite und Höhe ausfüllen.

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 Layout wie das unten schaut

<?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

try this: 'android: layout_gravity = "center_horizontal | center_vertical"' –

Antwort

2

Versuchen Sie, die folgenden Attribute zu Ihrem VideoView in Ihrem XML-Layout hinzufügen:

<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

Danke für die reply..its arbeiten .. –

+0

Gern @Lincy Laiju – Arshak

+0

Hey, ich habe Zweifel ... Das Video scheint gestreckt zu sein. Können wir etwas dagegen tun, oder sollte ich das Design-Team bitten, ein Video mit unterschiedlichen Proportionen für verschiedene Bildschirme bereitzustellen? –

0

gut, ich glaube, Sie müssen Sie Ihre Manifest-Datei bearbeiten und dort ein wenig Code hinzufügen:

"Ich hoffe, das funktioniert"

+0

Vielen Dank für die Antwort .. ich versuchte.Nur der obige Code wird nicht geben das Ergebnis... –