在Dialog的键盘消失后VideoView不能正确呈现

当我可以复制时,我将问题简化为最小的例子。

所以:

  • 1与VideoView和ImageView的活动。
  • 显示完成后,单击ImageView AlertDialog。
  • AlertDialog有1个EditText字段。
  • 我触摸这个EditText,并显示标准的Android键盘。
  • closures键盘。
  • closures对话框。

问题: VideoView的边框(黑色矩形)被扩展,因此ImageView不再显示。

任何帮助表示赞赏! 谢谢。

之前后

码:

MainActivity.java

import android.app.Activity; import android.app.AlertDialog; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.widget.VideoView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Activity act = this; final VideoView videoView = (VideoView) findViewById(R.id.videoView1); videoView.setVideoPath("/mnt/sdcard/s1ep01.mp4"); videoView.requestFocus(); findViewById(R.id.imageView1).setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { AlertDialog.Builder builder = new AlertDialog.Builder(act); View view = LayoutInflater.from(act).inflate(R.layout.dialog, null); builder.setView(view); builder.setPositiveButton("Save translation", null); builder.setNegativeButton("Cancel", null); AlertDialog dialog = builder.create(); dialog.show(); } }); } } 

activity_main.xml中

 <RelativeLayout 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=".MainActivity" > <VideoView android:id="@+id/videoView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" /> <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/videoView1" android:src="@android:drawable/btn_dialog" /> </RelativeLayout> 

dialog.xml

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" /> </RelativeLayout> 

作为一个临时解决scheme,我创build了一个使VideoView无形的Runnable,然后在200毫秒后使其可见:

 // Hide the VideoView videoLayout.setVisibility(View.INVISIBLE); // create a handler to handle the delayed runnable request new Handler().postDelayed(new Runnable() { @Override public void run() { // After the 200 millis (which are passes as a second parameter to this postDelayed() method in the last line of the code, this handler will invoke the following method : // run on UI so you can set the Visibitity of the UI elements runOnUiThread(new Runnable() { @Override public void run() {videoLayout.setVisibility(View.VISIBLE);} // make it visible again }); } }, 200); // this is the second parameter which decides when this handler will run it's run() method 

希望这个临时解决scheme现在有帮助

当你的键盘被隐藏的时候调用这个方法,像ENTER键一样,或者当你触摸键盘外的某个视图来隐藏它的时候…但是不要把它放在activity的onTouchEvent()或者onUserInteraction中,闪烁