Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中的一半或四分之一黑屏_Android_Android Activity - Fatal编程技术网

android中的一半或四分之一黑屏

android中的一半或四分之一黑屏,android,android-activity,Android,Android Activity,我有一个android活动,当我有时启动(大约四分之一次)时,它只会在屏幕上显示四分之一或一半。当我改变方向或按下按钮时,屏幕会正确绘制 我只是使用文本视图、按钮、字体——没有绘图或类似的东西 我初始化的所有代码都在onCreate()中。在这个方法中,我加载了一个大约40行长的文本文件,并且得到了一个共享的首选项。这是否会导致延迟,从而无法得出意图 如果有人看过类似的东西,请提前感谢 编辑-我尝试对单词列表的加载进行注释,但没有解决问题 编辑2-我没有设法解决这个问题,但通过在onCreate

我有一个android活动,当我有时启动(大约四分之一次)时,它只会在屏幕上显示四分之一或一半。当我改变方向或按下按钮时,屏幕会正确绘制

我只是使用文本视图、按钮、字体——没有绘图或类似的东西

我初始化的所有代码都在onCreate()中。在这个方法中,我加载了一个大约40行长的文本文件,并且得到了一个共享的首选项。这是否会导致延迟,从而无法得出意图

如果有人看过类似的东西,请提前感谢

编辑-我尝试对单词列表的加载进行注释,但没有解决问题

编辑2-我没有设法解决这个问题,但通过在onCreate的末尾添加一个计时器来改进它。我设置了一个低刷新率,并在勾选中更改了其中一个控件的文本。这似乎重新绘制了屏幕,去掉了屏幕的黑色部分

这里是活动

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainRelativeLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/blue_abstract_background" >

    <RelativeLayout
        android:id="@+id/relativeScore"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal" >

        <TextView
            android:id="@+id/ScoreLabel"
            style="@style/yellowShadowText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:padding="10dip"
            android:text="SCORE:"
            android:textSize="18dp" />
    />

        <TextView
            android:id="@+id/ScoreText"
            style="@style/yellowShadowText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@id/ScoreLabel"
            android:padding="5dip"
            android:text="0"
            android:textSize="18dp" />

        <TextView
            android:id="@+id/GameTimerText"
            style="@style/yellowShadowText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:minWidth="25dp"
            android:text="0"
            android:textSize="18dp" />

        <TextView
            android:id="@+id/GameTimerLabel"
            style="@style/yellowShadowText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@id/GameTimerText"
            android:padding="10dip"
            android:text="TIMER:"
            android:textSize="18dp" />
             />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeHighScore"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/relativeScore" >

        <TextView
            android:id="@+id/HighScoreLabel"
            style="@style/yellowShadowText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:padding="10dip"
            android:text="HIGH SCORE:"
            android:textSize="16dp" />

        <TextView
            android:id="@+id/HighScoreText"
            style="@style/yellowShadowText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/HighScoreLabel"
            android:padding="10dip"
            android:text="0"
            android:textSize="16dp" />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/relativeHighScore"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/linearMissing"
            android:layout_width="fill_parent"
            android:layout_height="80dp"
            android:layout_gravity="center"
            android:orientation="vertical" >

            <View
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="@color/yellow_text" />

            <TextView
                android:id="@+id/MissingWordText"
                style="@style/yellowShadowText"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="25dp"
                android:text="MSSNG WRD"
                android:textSize="22dp"
                android:typeface="normal" />
        </LinearLayout>

        <View
            android:layout_width="match_parent"
            android:layout_height="2dp"
            android:background="@color/yellow_text" />

        <TableLayout
            android:id="@+id/buttonsTableLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TableRow
                android:id="@+id/tableRow3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:paddingTop="5dp" >

                <Button
                    android:id="@+id/aVowelButton"
                    android:layout_width="66dp"
                    android:layout_height="66dp"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginBottom="10dp"
                    android:layout_marginRight="5dp"
                    android:background="@drawable/blue_vowel_button"
                    android:text="@string/a"
                    android:textColor="@color/yellow_text"
                    android:textSize="30dp" />

                <Button
                    android:id="@+id/eVowelButton"
                    android:layout_width="66dp"
                    android:layout_height="66dp"
                    android:layout_gravity="center_horizontal"
                    android:layout_marginBottom="10dp"
                    android:layout_marginRight="5dp"
                    android:background="@drawable/blue_vowel_button"
                    android:text="@string/e"
                    android:textColor="@color/yellow_text"
                    android:textSize="30dp" />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow4"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal" >

                <Button
                    android:id="@+id/iVowelButton"
                    android:layout_width="66dp"
                    android:layout_height="66dp"
                    android:layout_gravity="center_horizontal"
                    android:layout_margin="5dp"
                    android:background="@drawable/blue_vowel_buttoni"
                    android:text="@string/i"
                    android:textColor="@color/yellow_text"
                    android:textSize="30dp" />

                <Button
                    android:id="@+id/oVowelButton"
                    android:layout_width="66dp"
                    android:layout_height="66dp"
                    android:layout_gravity="center_horizontal"
                    android:layout_margin="5dp"
                    android:background="@drawable/blue_vowel_button"
                    android:text="@string/o"
                    android:textColor="@color/yellow_text"
                    android:textSize="30dp" />

                <Button
                    android:id="@+id/uVowelButton"
                    android:layout_width="66dp"
                    android:layout_height="66dp"
                    android:layout_gravity="center_horizontal"
                    android:layout_margin="5dp"
                    android:background="@drawable/blue_vowel_button"
                    android:text="@string/u"
                    android:textColor="@color/yellow_text"
                    android:textSize="30dp" />
            </TableRow>
        </TableLayout>

        <TextView
            android:id="@+id/TimeToStartText"
            style="@style/yellowShadowText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:textSize="24dp" />

        <Button
            android:id="@+id/startButton"
            style="@style/yellowShadowText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="10dp"
            android:background="@drawable/blue_button_menu"
            android:gravity="center"
            android:padding="10dip"
            android:text="START!"
            android:textSize="28dp" />
    </LinearLayout>

</RelativeLayout>

密码?布局?例子?我们只能猜测,没有什么东西可以看。atAs@mutmart说,如果你添加代码/布局会更好。测试它是否是文本文件的简单方法,只需注释掉代码中的文件解析部分,看看这是否会使它消失。在UI线程(onCreate()处于启用状态)上加载文本文件可能不是您的最佳选择(即使这不是您的主要问题),请检查AsyncTask以处理该问题。正如Mutmart所说。。。你真的应该在这里发布一些代码同样的问题有什么解决方案吗?
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_game);
    isNewWord = true; 
    m_gameScore = 0; 
    m_category = getCategoryFromExtras();           
    //   loadWordList(m_category); 
    initialiseTextViewField(); 
    loadHighScoreAndDifficulty(); 
    setFonts();
    setButtons(); 


    setStartButton(); 

    enableDisableButtons(false); 


}

private void loadHighScoreAndDifficulty() {
    //setting preferences
    SharedPreferences prefs = this.getSharedPreferences(m_category, Context.MODE_PRIVATE);
    int score = prefs.getInt(m_category, 0); //0 is the default value
    m_highScore = score; 
    m_highScoreText.setText(String.valueOf(m_highScore)); 

    prefs = this.getSharedPreferences(DIFFICULTY, Context.MODE_PRIVATE);
    m_difficulty = prefs.getString(DIFFICULTY, NRML_DIFFICULTY); 

}

private void initialiseTextViewField() {
    m_startButton = (Button) findViewById(R.id.startButton);
    m_missingWordText = (TextView) findViewById(R.id.MissingWordText); 
    m_gameScoreText = (TextView) findViewById(R.id.ScoreText); 
    m_gameScoreLabel = (TextView) findViewById(R.id.ScoreLabel); 
    m_gameTimerText = (TextView) findViewById(R.id.GameTimerText); 
    m_gameTimerLabel = (TextView) findViewById(R.id.GameTimerLabel); 
    m_timeToStartText = (TextView) findViewById(R.id.TimeToStartText);
    m_highScoreLabel = (TextView) findViewById(R.id.HighScoreLabel); 
    m_highScoreText = (TextView) findViewById(R.id.HighScoreText);
}

private String getCategoryFromExtras() {
    String category = ""; 
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        category = extras.getString("category");
    }
    return category;
}

private void enableDisableButtons(boolean enable) {
    Button button = (Button) findViewById(R.id.aVowelButton);
    button.setEnabled(enable);
    button = (Button) findViewById(R.id.eVowelButton);
    button.setEnabled(enable);
    button = (Button) findViewById(R.id.iVowelButton);
    button.setEnabled(enable);
    button = (Button) findViewById(R.id.oVowelButton);
    button.setEnabled(enable);
    button = (Button) findViewById(R.id.uVowelButton);
    button.setEnabled(enable);
}

private void setStartButton() {
    m_startButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {

            m_gameScore = 0; 
            updateScore(); 
            m_startButton.setVisibility(View.GONE);
            m_timeToStartText.setVisibility(View.VISIBLE);
            startPreTimer(); 
        }

    });

}