8

I simplified my problem to the smallest example when it can be reproduced.

So:

  • 1 activity with VideoView and ImageView.
  • After clicking on ImageView AlertDialog is showed.
  • AlertDialog have 1 EditText field.
  • I touch this EditText and standard Android keyboard is showed.
  • Close keyboard.
  • Close dialog.

Problem: VideoView's borders (black rectangle) were extended and thus ImageView is not showed anymore.

Any help is appreciated! Thanks.

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>
kolobok
  • 3,835
  • 3
  • 38
  • 54

1 Answers1

3

as a Temporary solution, i created a Runnable that makes the VideoView Invisible, then makes it Visible after 200 milli seconds :

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

hope this temporary solution helps for now

call this methods when your keyboard is hiding, alike on ENTER key, or when you touch a certain view outside the keyboard to hide it ... but dont put it in the onTouchEvent() of the activity or in the onUserInteraction so not to keep flashing

Ahmed Adel Ismail
  • 2,168
  • 16
  • 23
  • 1- Read my comment on the question. 2- I think calling `requestLayout();` is enough instead of posting a delayed runnable. – Sherif elKhatib Sep 26 '13 at 15:50
  • but if it adjusts nothing, my edit text will be covered by the soft input keyboard !? ... i'll try the requestLayout() instead of posting a runnable ... you mean using it in the same situations instead ... thats what i understood from you – Ahmed Adel Ismail Sep 27 '13 at 15:21
  • 1
    Just play around with the `android:windowSoftInputMode`. I think this might do the job for you: http://www.sherif.mobi/2011/10/softkeyboard-problem-with-tabhost-on.html – Sherif elKhatib Sep 27 '13 at 15:44
  • @SherifelKhatib as i told you, adjustNothing hides the Edit text, and requestLayout() does nothing, either calling it from the Layout wrapping the VideView, or calling it from the the VideView itself – Ahmed Adel Ismail Sep 30 '13 at 07:34
  • Actually, I think you did not click the link :P. It advices: `android:windowSoftInputMode="adjustPan|adjustResize"` – Sherif elKhatib Sep 30 '13 at 07:46
  • i clicked and tried, it is the same as adjustNothing (in effect) :) – Ahmed Adel Ismail Sep 30 '13 at 09:38