I would like to programmatically add a VideoView to a LinearLayout. The LinearLayout has an id of "main".
Referencing this SO question Video Streaming and Android, I was able to get the video to show up and play, but what if I wanted to create a new VideoView on the fly and add it to the layout?
This is the XML I am trying to "copy" programmatically:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/main"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent">
<VideoView android:id="@+id/your_video_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
Here is how I tried to accomplish the same thing programmatically:
VideoView videoView = new VideoView(this);
LinearLayout layout = (LinearLayout)findViewById(R.id.main);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layout.addView(videoView, params);
The problem is that the video doesn't show up at all! With VideoView declared in XML, everything works fine, but programmatically, it doesn't work at all.
To be clear, I do not want to have a VideoView defined in the XML file when I am doing it programmatically.