我有一个绘图应用程序需要大约2-5秒来加载复杂图纸的绘图(通过一个完成AsyncTask).为了获得更好的用户体验,在此期间我将应用程序目录中存储的PNG版本作为一个闪存ImageView,并在Activity构造函数中显示加载ProgressBar调用setContentView():
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/flash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@color/note_bg_white"
android:contentDescription="@string/content_desc_flash_img"
android:focusable="false" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="6dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:gravity="bottom|center_vertical">
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:id="@+id/toolbar_progress"
android:layout_width="match_parent"
android:layout_height="18dp"
android:gravity="bottom|center_vertical" />
</RelativeLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
当AsyncTask完成后,我再调用setContentView()的新布局再次:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<com.my.package.DrawingCanvas
android:id="@+id/canvas"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:background="#ffffff" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
当我使用一个简单的Canvas模型时,这非常有效,因为自定义DrawingCanvas View会onDraw()在向用户显示之前将绘图绘制到初始屏幕上,但现在使用SurfaceView带有绘图循环,我看到闪烁的布局,然后加载图形时,黑屏大约一秒钟,最后是新的DrawingCanvas.
我假设原因与绘制循环线程的启动时间有关,并且我已经离开了我onDraw()的内部SurfaceView,并且它被调用,但是可用的画布onDraw()似乎没有绘制到SurfaceView.我也尝试在XML中设置纯色背景,希望至少能够显示白色背景,但这些背景似乎永远不会生效,甚至从代码设置它. …
我正面临着奇怪的闪烁问题VideoView.当活动开始时,它会导致轻微的分数闪烁一秒钟.然后,视频开始.它在视频的顶部和底部显示2条黑线.请参阅下面的快照.

我在2台设备上测试了我的应用程序
1)三星n-8000(平板电脑)
2)联想a-800
video.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:gravity="center">
<VideoView
android:id="@+id/vvSplash"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#00ffffff">
</VideoView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
活动代码:
private VideoView vd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.video);
vd = (VideoView) findViewById(R.id.vvSplash);
playVideo();
}
private void playVideo() {
Uri uri = Uri.parse("android.resource://" + getPackageName() +"/"+ R.raw.intro);
vd.setVideoURI(uri);
vd.setMediaController(null);
vd.start();
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.谢谢.
I didn't use a real device, I was working on emulator. (Problem Solved)
Run Code Online (Sandbox Code Playgroud)
我正在开发一个直播视频应用程序.我有很多直播网址,其中包含*.m3u8后缀.
当我启动应用程序时,我只能听到声音,但没有视频显示.视频显示区域总是很暗.
我正在等待你的有用建议来解决我的问题.
问候.
我的一些代码:
public class MainActivity extends Activity {
private static ProgressDialog progressDialog;
String videourl = "URL/playlist.m3u8";
VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = (VideoView) findViewById(R.id.video_View);
progressDialog = ProgressDialog.show(MainActivity.this, "", "Buffering video...", true);
progressDialog.setCancelable(false);
PlayVideo();
}
private void PlayVideo() {
try {
getWindow().setFormat(PixelFormat.TRANSLUCENT);
MediaController mediaController = new MediaController(MainActivity.this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse(videourl);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.requestFocus();
videoView.setVisibility(View.VISIBLE);
videoView.setOnPreparedListener(new OnPreparedListener() { …Run Code Online (Sandbox Code Playgroud)