首先,我已经看过网站上的类似问题,他们没有帮助。我使用FrameLayout,并尝试点击自定义ImageView,使图像视图不可见和视频开始播放,但是当我点击ImageView时,只有一个空白屏幕出现,没有视频/音频播放。Android VideoView没有显示在不同的布局
feedImageView.setOnClickListener(new OnClickListener() {
String substrr=item.getURL();
@Override
public void onClick(View v) {
feedImageView.setVisibility(View.INVISIBLE);
vid.setVisibility(View.VISIBLE);
Uri vidUri = Uri.parse(substrr);
vid.setVideoURI(vidUri);
MediaController vidControl = new MediaController(getActivity());
vidControl.setAnchorView(vid);
vid.setMediaController(vidControl);
vid.start();
});
完整的布局,他们走的是下面 -
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.videoplayer.MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/myPic"
android:src="@drawable/icon"
/>
<VideoView
android:id="@+id/myVideo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:visibility="invisible"/>
</FrameLayout>
请帮助 -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/feed_bg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="@dimen/feed_item_margin"
android:layout_marginRight="@dimen/feed_item_margin"
android:layout_marginTop="@dimen/feed_item_margin"
android:background="@drawable/bg_parent_rounded_corner"
android:orientation="vertical"
android:paddingBottom="@dimen/feed_item_padding_top_bottom"
android:paddingTop="@dimen/feed_item_padding_top_bottom" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="@dimen/feed_item_padding_left_right"
android:paddingRight="@dimen/feed_item_padding_left_right" >
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/profilePic"
android:layout_width="@dimen/feed_item_profile_pic"
android:layout_height="@dimen/feed_item_profile_pic"
android:scaleType="fitCenter" >
</com.android.volley.toolbox.NetworkImageView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center"
android:paddingLeft="@dimen/feed_item_profile_info_padd" >
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/feed_item_profile_name"
android:textColor="#0f84cc"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<-- THIS IS THE FRAME LAYOUT CONCERNED WITH THE QUESTION-->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.example.android.FeedImageView
android:id="@+id/feedImage1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:layout_marginTop="10dp"
android:scaleType="fitXY"
android:visibility="visible" />
<VideoView
android:id="@+id/vid12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
/>
</FrameLayout>
<TextView
android:id="@+id/txtStatusMsg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/feed_item_status_pad_left_right"
android:paddingRight="@dimen/feed_item_status_pad_left_right"
android:paddingTop="@dimen/feed_item_status_pad_top" />
<Button
android:id="@+id/downloadbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Download"
android:textColor="#ffffff"
android:gravity="center"
android:padding="10dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:background="#0f84cc"
/>
</LinearLayout>
</LinearLayout>
现在如果我用Java代码与以下布局的视频作品。
你有什么错误? –
@Shoeb Siddique没有error.I只是无法让VideoView在第一个布局中出现,我也没有任何声音。 – zek54