Android VideoView与ImageView

Android VideoView与ImageView,android,android-videoview,Android,Android Videoview,我想单击图像并设置VideoView的可见性,使imageView不可见。但是,当我单击图像时,会出现白色背景。请帮助。 imageView和videoView的布局 完整布局文件- 不使用不可见的用法: 替换: feedImageView.setVisibility(View.INVISIBLE); 与: 为了使图像和视频一个接一个地堆叠在一起,您应该将它们放在如下容器中: <FrameLayout android:layout_width="match_parent

我想单击图像并设置VideoView的可见性,使imageView不可见。但是,当我单击图像时,会出现白色背景。请帮助。

imageView和videoView的布局


完整布局文件-


不使用不可见的用法:

替换:

feedImageView.setVisibility(View.INVISIBLE);
与:


为了使图像和视频一个接一个地堆叠在一起,您应该将它们放在如下容器中:

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<com.example.adapter.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/vid"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="10dp"
            android:visibility="invisible"
             />
</FrameLayout>


请注意,视频的高度为
match_parent
以使其与初始图像大小相同

使用您的方法,ImageView会折叠,但VideoView不会出现。logcat中是否有异常情况?yu 100%确定您使用的URI是正确的吗?@KirillK使用Logcat获取URI及其mp4格式-URI正常,然后请发布完整的布局file@KirillK我已经放置了完整的布局文件。如果需要,请建议任何更改。初始布局后,视频的初始高度为0,并保持不变。如果我理解正确,你想用视频替换你的图像吗?然后看我的答案。我已经按照你的解决方案做了,但是在ImageView崩溃后,视频视图就不可见了。你听到视频声音了吗?你有没有在清单中申请互联网许可,以便下载视频?我有所有必要的许可,实际上,我正在制作一个类似instagram的项目,我从feed中获取图片,但无法将视频放在已定义的图像视图中,因此希望在单击imageview时获取视频视图。此外,我在单击时听不到声音。试着在
videoView
上设置各种侦听器,这样可以帮助您调试/弄清楚发生了什么
<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>

       <!--  <VideoView
            android:id="@+id/feedImage1"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_marginTop="15dp"
           android:background="#000000"
             /> -->

            <com.example.adapter.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/vid"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
             />

         <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>
feedImageView.setVisibility(View.INVISIBLE);
feedImageView.setVisibility(View.GONE);
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<com.example.adapter.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/vid"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="10dp"
            android:visibility="invisible"
             />
</FrameLayout>