问题
I'm fairly new to Android and I recently added a CardView
to my app to display a few text boxes and images, which work just fine.
However, when I tried to display a video the card remains empty. Can someone help me understand what am I doing wrong?
I've defined the ImageView
like so:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/card_margin"
android:layout_marginLeft="@dimen/card_margin"
android:layout_marginRight="@dimen/card_margin">
<LinearLayout
style="@style/Widget.CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<VideoView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="@+id/step1Vid" />
<MediaController
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/mediaController2"
android:layout_below="@id/step1Vid" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/step_image"/>
</LinearLayout>
</android.support.v7.widget.CardView>
initially i tried to set the video in the onCreate of the relevant Activity like so:
VideoView video = (VideoView) findViewById(R.id.step1Vid);
Uri vidUri = Uri.parse(SOME_MP4_URL);
video.setVideoURI(vidUri);
MediaController mCon = new MediaController(getApplicationContext());
mCon.setAnchorView(video);
video.setMediaController(mCon);
That didn't work not sure why. so Then from the relevant Activity
I used AsyncTask
to get a video from a URL. used the same code inside the onProgressMethod because of the UI changes which didn't work either.
I would appreciate any advice I can get.
回答1:
problem was solved when i gave the LinearLayout a fixed size instead of using the "wrap_content" attribute.
来源:https://stackoverflow.com/questions/31973463/how-to-display-a-video-in-a-cardview-on-android