如何显示在Android上CardView视频? [英] How to display a video in a CardView on Android?
问题描述
我是相当新的Android和我最近增加了一个 CardView
来我的应用程序来显示一些文本框和图像,这工作得很好。
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?
我所定义的的ImageView
像这样:
<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>
起初我试图设置在相关活动的OnCreate像这样的视频:
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);
这不工作不知道为什么。于是从相关活动
我用的AsyncTask
来得到一个URL的视频。由于使用的UI变化onProgressMethod内同一code这也不能工作。
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.
我想AP preciate任何意见,我可以得到的。
I would appreciate any advice I can get.
推荐答案
当我给的,而不是用WRAP_CONTENT属性的LinearLayout一个固定大小的问题得到解决。
problem was solved when i gave the LinearLayout a fixed size instead of using the "wrap_content" attribute.
这篇关于如何显示在Android上CardView视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!