作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我是 Android 的新手,最近我在我的应用程序中添加了一个 CardView
来显示一些文本框和图像,效果很好。
但是,当我尝试显示视频时,卡片仍然是空的。有人可以帮助我了解我做错了什么吗?
我已经像这样定义了 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>
最初我尝试像这样在相关 Activity 的 onCreate 中设置视频:
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);
那不工作不知道为什么。所以然后从相关的 Activity
我使用 AsyncTask
从 URL 获取视频。由于 UI 更改也不起作用,因此在 onProgressMethod 中使用了相同的代码。
如果我能得到任何建议,我将不胜感激。
最佳答案
当我给 LinearLayout 一个固定大小而不是使用“wrap_content”属性时,问题就解决了。
关于android - 如何在 Android 的 CardView 中显示视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31973463/
我是一名优秀的程序员,十分优秀!