在Dialog的键盘消失后,VideoView无法正确呈现

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

所以:

  • 使用VideoView和ImageView进行1项活动。
  • 点击ImageView后显示AlertDialog。
  • AlertDialog有1个EditText字段。
  • 我触摸了这个EditText,显示了标准的Android键盘。
  • 关闭键盘。
  • 关闭对话框。

问题: 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中

     

dialog.xml

     

作为一个临时解决方案,我创建了一个Runnable,使VideoView不可见,然后在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 

希望这个临时解决方案现在有所帮助

键盘隐藏时调用此方法,类似于ENTER键,或者当您触摸键盘外部的某个视图以隐藏它时…但是不要将它放在活动的onTouchEvent()或onUserInteraction中,以免保留闪烁