表面与我的图像重叠

时间:2016-03-02 08:33:06

标签: android

当我按下音量键时,我想要在我的GLSurface视图上显示一个图像。

然而,

表面与图像重叠。 有时一段时间后,图像被带到前面,所以我不知道它是如何发生的。

这是我的xml(我的渲染器使用双视口):

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/FrameLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:mContext="main.ViewManager" >

    <RelativeLayout
        android:id="@+id/screen"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/Layout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/mic_1"
            android:src="@drawable/ico_mic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            android:visibility="invisible" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/Layout2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/mic_2"
            android:src="@drawable/ico_mic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            android:visibility="invisible" />

    </RelativeLayout>

</FrameLayout>

这是我的主要活动&#39; onCreate:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //keep screen turned on
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    //set surface
    surface = new MySurface(this);

    //set views
    setContentView(R.layout.activity_main);
    mMicImage1 = (ImageView) findViewById(R.id.mic_1);
    mMicImage2 = (ImageView) findViewById(R.id.mic_2);
    RelativeLayout screen = (RelativeLayout) findViewById(R.id.screen);
    screen.removeAllViews();
    screen.addView(mL4BSurface, RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
}

这是我对音量键击的实现:

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    int action = event.getAction();
    int keyCode = event.getKeyCode();
    switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (action == KeyEvent.ACTION_DOWN) {
                Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
                intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
                intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,"voice.recognition.test");
                intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
                mMicImage1.setVisibility(View.VISIBLE);
                mMicImage2.setVisibility(View.VISIBLE);
                //mSpeechRecognizer.startListening(intent);
            }
            return true;
        default:
            return super.dispatchKeyEvent(event);
    }
}

0 个答案:

没有答案