我已经使用片段为galaxy tab创建了一个应用程序。我有一个片段的视频视图,可以从外部存储中添加视频。
以下是该片段的代码 -
package com.example.hscroll.demo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.widget.RelativeLayout;
import android.widget.VideoView;
public class FragmentVideo1 extends Fragment implements OnTouchListener{
LayoutInflater inflater;
private VideoView video;
private MediaController ctlr;
int length = 0;
boolean isPlaying = false;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance)
{
this.inflater = inflater;
if(container == null)return null;
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
{
container = (LinearLayout)inflater.inflate(R.layout.video, container, false);
video=(VideoView)container.findViewById(R.id.video);
video.setVideoPath("/mnt/sdcard/Ideal Solar/video1.mp4");
ctlr=new MediaController(inflater.getContext());
ctlr.setMediaPlayer(video);
video.setMediaController(ctlr);
video.requestFocus();
}else
{
container = (RelativeLayout)inflater.inflate(R.layout.video_land, container, false);
video=(VideoView)container.findViewById(R.id.myVideo_land);
video.setVideoPath("/mnt/sdcard/Ideal Solar/video1.mp4");
ctlr=new MediaController(inflater.getContext());
ctlr.setMediaPlayer(video);
video.setMediaController(ctlr);
video.requestFocus();
video.start();
}
return container;
}
}
当我来到这个视频片段之前的片段时,它会闪烁一次(就像视频片段在这个片段下方可见)。它只是第一次发生。如果我回去再来这个片段就不会眨眼。
视频片段前片段的代码 -
package com.example.hscroll.demo;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import com.example.hscroll.customer.BitmapWeakReference;
import com.example.hscroll.library.imagezoom.ImageViewTouch;
public class Fragment2 extends Fragment{
ImageViewTouch imgview ;
LayoutInflater inflater;
FileInputStream in;
BufferedInputStream buf;
BitmapWeakReference bitmap;
ViewGroup con;
static Fragment2 frag2;
public static Fragment2 newInstance(int num)
{
if(frag2 == null)
frag2 = new Fragment2();
return frag2;
}
private final String PATH = "/mnt/sdcard/Ideal Solar/page_03.png";
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance)
{
this.inflater = inflater;
if(container == null)return null;
container = (LinearLayout)inflater.inflate(R.layout.fragment0_layout, container, false);
con = container;
imgview= (ImageViewTouch)container.findViewById(R.id.imageView1);
bitmap = new BitmapWeakReference(imgview.selectImage(inflater.getContext(), PATH));
if(bitmap!=null)
imgview.setImageBitmapReset( bitmap.get(), true );
return container;
}
@Override
public void onDestroyView() {
super.onDestroyView();
imgview.setImageBitmap(null);
bitmap.clear();
bitmap = null;
Fragment1.unbindDrawables(con.findViewById(R.id.ll));
System.gc();
}
}
我只是在这个片段上显示一个图像。
视频片段的XML -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/header"
android:background="@drawable/video_header"/>
<VideoView
android:id="@+id/video"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
提前感谢任何可以提供帮助的人。
答案 0 :(得分:6)
VideoView继承自SurfaceView,SurfaceView导致此问题。 尝试在应用加载时(在onCreate ...中)向mainView添加虚拟SurfaceView。 为我解决了这个问题。