Android Activity闪烁

时间:2014-05-21 15:41:37

标签: java android android-studio flicker

在这个xml中,每当我进入活动时,屏幕都会闪烁, 像Goes black一样奇怪地行动,然后恢复正常,然后再次变黑,重复...

<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"
    android:id="@+id/fullscreen_content"
    android:background="#ff282bff"
    android:fitsSystemWindows="true"
    android:keepScreenOn="true"
    android:gravity="center"
    tools:context="com.luiscesjr.aquariodebolso.aquariodebolso.infomenu">



   <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/fullscreen_content_controls"
    android:fitsSystemWindows="true"
    android:keepScreenOn="true"
    android:gravity="center"


    <ImageButton
        android:layout_width="120dp"
        android:layout_height="150dp"
        android:id="@+id/button7"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:src="@drawable/calendar128"
        />

    <ImageButton
        android:layout_width="120dp"
        android:layout_height="150dp"
        android:id="@+id/button8"
        android:layout_alignParentTop="true"
        android:layout_alignLeft="@+id/button11"
        android:layout_alignStart="@+id/button11"
        android:src="@drawable/fish128"/>

    <ImageButton
        android:layout_width="120dp"
        android:layout_height="150dp"
        android:id="@+id/button9"
        android:layout_alignParentTop="true"
        android:layout_alignLeft="@+id/button12"
        android:layout_alignStart="@+id/button12"
        android:src="@drawable/clown_fish128"/>

    <ImageButton
        android:layout_width="120dp"
        android:layout_height="150dp"
        android:id="@+id/button10"
        android:layout_marginTop="102dp"
        android:layout_below="@+id/button7"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:src="@drawable/ruler128"/>

    <ImageButton
        android:layout_width="120dp"
        android:layout_height="150dp"
        android:id="@+id/button11"
        android:layout_alignTop="@+id/button10"
        android:layout_centerHorizontal="true"
        android:src="@drawable/ruler128"/>

    <ImageButton
        android:layout_width="120dp"
        android:layout_height="150dp"
        android:id="@+id/button12"
        android:layout_alignTop="@+id/button11"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:src="@drawable/ruler128"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Calendário"
        android:id="@+id/textView"
        android:layout_below="@+id/button7"
        android:layout_alignRight="@+id/textView4"
        android:layout_alignEnd="@+id/textView4" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Aqua Doce"
        android:id="@+id/textView2"
        android:layout_below="@+id/button8"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Aqua Marinho"
        android:id="@+id/textView3"
        android:layout_below="@+id/button9"
        android:layout_alignLeft="@+id/button9"
        android:layout_alignStart="@+id/button9" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Ferramentas"
        android:id="@+id/textView4"
        android:layout_below="@+id/button10"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Medium Text"
        android:id="@+id/textView5"
        android:layout_below="@+id/button11"
        android:layout_alignRight="@+id/button11"
        android:layout_alignEnd="@+id/button11" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Medium Text"
        android:id="@+id/textView6"
        android:layout_below="@+id/button12"
        android:layout_alignLeft="@+id/button12"
        android:layout_alignStart="@+id/button12" />

    <!-- This FrameLayout insets its children based on system windows using
         android:fitsSystemWindows. -->

 </RelativeLayout>
</RelativeLayout>

这就是它所引用的代码。:

package com.luiscesjr.aquariodebolso.aquariodebolso;

import com.luiscesjr.aquariodebolso.aquariodebolso.util.SystemUiHider;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.graphics.drawable.AnimationDrawable;


public class infomenu extends Activity {

    private static final boolean AUTO_HIDE = true;
    private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
    private static final boolean TOGGLE_ON_CLICK = true;
    private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;
    private SystemUiHider mSystemUiHider;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_infomenu);
        setupActionBar();

        final View controlsView = findViewById(R.id.fullscreen_content_controls);
        final View contentView = findViewById(R.id.fullscreen_content);

        mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS);
        mSystemUiHider.setup();
        mSystemUiHider
                .setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
                    // Cached values.
                    int mControlsHeight;
                    int mShortAnimTime;

                    @Override
                    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
                    public void onVisibilityChange(boolean visible) {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {

                            if (mControlsHeight == ) {
   // LINE 83 HERE              mControlsHeight = controlsView.getHeight(); 
                            }
                            if (mShortAnimTime == 0) {
                                mShortAnimTime = getResources().getInteger(
                                        android.R.integer.config_shortAnimTime);
                            }
                            controlsView.animate()
                                    .translationY(visible ? 0 : mControlsHeight)
                                    .setDuration(mShortAnimTime);
                        } else {

                            controlsView.setVisibility(visible ? View.VISIBLE : View.GONE);
                        }

                        if (visible) {

                            delayedHide(AUTO_HIDE_DELAY_MILLIS);
                        }
                    }
                });


        contentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (TOGGLE_ON_CLICK) {
                    mSystemUiHider.toggle();
                } else {
                    mSystemUiHider.show();
                }
            }
        });
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);

        delayedHide(100);
    }


    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void setupActionBar() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

            getActionBar().setDisplayHomeAsUpEnabled(true);
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == android.R.id.home) {

            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (AUTO_HIDE) {
                delayedHide(AUTO_HIDE_DELAY_MILLIS);
            }
            return false;
        }
    };

    Handler mHideHandler = new Handler();
    Runnable mHideRunnable = new Runnable() {
        @Override
        public void run() {
            mSystemUiHider.hide();
        }
    };


    private void delayedHide(int delayMillis) {
        mHideHandler.removeCallbacks(mHideRunnable);
        mHideHandler.postDelayed(mHideRunnable, delayMillis);
    }
}

有没有人经历过这个?还是喜欢它?代码运行,不会崩溃等。 但我有这些闪烁。 在此先感谢大家!

0 个答案:

没有答案