Android 在CardView中播放视频
我有几张卡片放在回收站里。每张卡都有一个自定义的视频视图。单击视频视图时,视频应开始。然而,在我的例子中,它只是显示蓝色边框,视频没有运行。代码如下所示: custom_card_view.xml:Android 在CardView中播放视频,android,android-video-player,android-recyclerview,android-videoview,android-cardview,Android,Android Video Player,Android Recyclerview,Android Videoview,Android Cardview,我有几张卡片放在回收站里。每张卡都有一个自定义的视频视图。单击视频视图时,视频应开始。然而,在我的例子中,它只是显示蓝色边框,视频没有运行。代码如下所示: custom_card_view.xml: <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="5dip"
card_view:cardCornerRadius="4dp">
<com.test.components.CustomVideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/info_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dip"
/>
</android.support.v7.widget.CardView>
主要活动:
public class MainActivity extends ActionBarActivity {
RecyclerView.LayoutManager mLayoutManager = null;
RecyclerView mCardsRecyclerView = null;
RecyclerView.Adapter mAdapter = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initComponents();
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mCardsRecyclerView.setHasFixedSize(true);
mCardsRecyclerView.setLayoutManager(mLayoutManager);
mCardsRecyclerView.setAdapter(mAdapter);
}
/**
* Initialize all ui components/widgets/elements
*/
private void initComponents() {
mCardsRecyclerView = (RecyclerView) findViewById(R.id.cardsListView);
mLayoutManager = new LinearLayoutManager(this);
mAdapter = new NewsFeedAdapter();
}
}
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/AppTheme"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/cardsListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/alertButton" />
</RelativeLayout>
我希望每张卡最初只显示一个缩略图。单击视频后,相关卡应启动视频(不是所有卡)。视频开始时,VideoView应占据整个屏幕。我怎样才能做到这一点
谢谢 我也有同样的问题。另一个问题的答案,帮我解决了。这是通过在VideoView中给出高度(或宽度或两者)的显式值。比如说
<VideoView
android:id="@+id/mVideoView"
android:layout_width="match_parent"
android:layout_height="300dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"/>
这方面有什么进展吗?没有。不得不暂停。
<VideoView
android:id="@+id/mVideoView"
android:layout_width="match_parent"
android:layout_height="300dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"/>