gpt4 book ai didi

android - 如何在 Android 的 CardView 中显示视频?

转载 作者:太空狗 更新时间:2023-10-29 15:26:17 30 4
gpt4 key购买 nike

我是 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com