我想點擊一個圖像,並設置VideoView的可見性,並使imageView不可見。但是,當我點擊圖像白色nbackground出現。請幫助。 Android VideoView與ImageView
feedImageView.setOnClickListener(new OnClickListener() {
String substr2 =item.getImge().substring(item.getImge().length() - 3);
@Override
public void onClick(View v) {
if(item.getImge()!=null)
{
if(substr2.equals("jpg"))
{
Log.e(TAG,"Its image");
}
else if(substr2.equals("mp4"))
{
feedImageView.setVisibility(View.INVISIBLE);
MediaController mc=new MediaController(getActivity());
mc.setAnchorView(vid);
mc.setMediaPlayer(vid);
Log.e(TAG,"In mp4 "+item.getImge());
Uri uri = Uri.parse(item.getImge());
vid.setMediaController(mc);
vid.setVideoURI(uri);
vid.setVisibility(View.VISIBLE);
vid.start();
Log.e(TAG, "Its video");
}
}
}
});
佈局中的ImageView和videoView
<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"
android:scaleType="fitXY"
android:visibility="invisible" />
完整的佈局文件 -
<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>
logcat中的任何異常?你是否100%確定你使用的URI是正確的? –
@KirillK使用Logcat獲取uri及其mp4格式 - URI是https://scontent.cdninstagram.com/t50.2886-16/12708125_217442355268913_651092529_n.mp4 – zek54
好的,那麼請發佈完整的佈局文件 –