2013-07-24 28 views
8

Tôi đã đơn giản hóa vấn đề của mình thành ví dụ nhỏ nhất khi có thể sao chép.VideoView không được hiển thị chính xác sau khi bàn phím của Dialog biến mất

Vì vậy:

  • 1 hoạt động với VideoView và ImageView.
  • Sau khi nhấp vào ImageView AlertDialog được hiển thị.
  • AlertDialog có 1 trường EditText.
  • Tôi chạm vào EditText này và bàn phím Android chuẩn được hiển thị.
  • Đóng bàn phím.
  • Đóng hộp thoại.

Vấn đề: biên giới VideoView của (hình chữ nhật màu đen) đã được mở rộng và do đó ImageView không thấy nữa.

Mọi trợ giúp đều được đánh giá cao! Cảm ơn.

BEFORE AFTER

Code:

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

Tôi nghĩ rằng an toàn trong trường hợp này là để thêm vào hoạt động của bạn trong tệp kê khai 'android: windowSoftInputMode =" adjustNothing "'. –

Trả lời

3

như một giải pháp tạm thời, tôi đã tạo ra một Runnable mà làm cho các VideoView vô hình, sau đó làm cho nó có thể nhìn thấy sau 200 milli giây:

// 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 

hy vọng giải pháp tạm thời này sẽ giúp cho bây giờ

cuộc gọi này khi bàn phím của bạn ẩn, giống như phím ENTER hoặc khi bạn chạm vào một chế độ xem nhất định bên ngoài bàn phím để ẩn nó ... nhưng không đặt nó trong onTouchEvent() của hoạt động hoặc trong onUserInteraction để không tiếp tục nhấp nháy

+0

1- Đọc nhận xét của tôi về câu hỏi. 2 - Tôi nghĩ rằng gọi 'requestLayout();' là đủ thay vì gửi một runnable bị trì hoãn. –

+0

nhưng nếu nó không điều chỉnh gì, văn bản chỉnh sửa của tôi sẽ được bàn phím mềm nhập vào! ... Tôi sẽ thử requestLayout() thay vì đăng một runnable ... bạn có nghĩa là sử dụng nó trong các tình huống tương tự thay vào đó ... thats những gì tôi hiểu từ bạn –

+1

Chỉ cần chơi xung quanh với 'android: windowSoftInputMode'. Tôi nghĩ rằng điều này có thể làm công việc cho bạn: http://www.sherif.mobi/2011/10/softkeyboard-problem-with-tabhost-on.html –

Các vấn đề liên quan