2013-07-24 47 views
8

我將問題簡化爲可以複製的最小示例。Dialog的鍵盤消失後,VideoView顯示不正確

所以:有VideoView和ImageView的

  • 1活動。
  • 顯示了單擊ImageView AlertDialog後。
  • AlertDialog有1個EditText字段。
  • 我觸摸這個EditText並顯示標準的Android鍵盤。
  • 關閉鍵盤。
  • 關閉對話框。

問題: VideoView的邊界(黑色矩形)進行了擴展,因此ImageView的是不再顯示。

任何幫助表示讚賞!謝謝。

BEFORE AFTER

代碼:

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> 
+0

我認爲在這種情況下添加到清單中的活動「android:windowSoftInputMode =」adjustNothing「'是安全的。 –

回答

3

作爲臨時解決方案,我創建了一個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中,以免閃爍

+0

1-閱讀我對該問題的評論。我認爲調用'requestLayout();'是足夠的,而不是發佈延遲的可運行。 –

+0

但如果它不進行任何調整,我的編輯文本將被軟輸入鍵盤覆蓋! ...我會嘗試requestLayout(),而不是張貼runnable ...你的意思是在相同的情況下使用它...多數民衆贊成在我所知道的你 –

+1

只是玩'android:windowSoftInputMode'。我認爲這可能適合你:http://www.sherif.mobi/2011/10/softkeyboard-problem-with-tabhost-on.html –