显示一个黑色的屏幕在我的Andr​​oid应用程序 - 在Eclipse我的、应用程序、屏幕、黑色

2023-09-04 03:11:27 作者:故酒

我在编程为Android初学者,我有一个很大的问题。 使用的开发环境Eclispe的。创建秒表应用程序,但 总是在我的应用程序只显示黑屏。由于项目的创建了我的手机的开始是通过一个Android亚行只显示黑屏连接。我看了看这个网站的一些线程,但我仍然不知道是什么问题。

I am a beginner in programming for Android and I have a big problem. Use development environment Eclispe. Creating stopwatch application, but always in my application displays only a black screen. Since the beginning of the creation of the project over my phone is connected via an Android ADB in shows only a black screen. I looked at some threads on this site, but I still do not know what the problem is.

我的 MainActivity.java 文件:

package cz.miegl.stopky;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

    private TextView textTimer;
    private Button startButton;
    private Button pauseButton;
    private long startTime = 0L;
    private Handler myHandler = new Handler();
    long timeInMillies = 0L;
    long timeSwap = 0L;
    long finalTime = 0L;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textTimer = (TextView) findViewById(R.id.textTimer);

        startButton = (Button) findViewById(R.id.btnStart);
        startButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                startTime = SystemClock.uptimeMillis();
                myHandler.postDelayed(updateTimerMethod, 0);

            }
        });

        pauseButton = (Button) findViewById(R.id.btnPause);
        pauseButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                timeSwap += timeInMillies;
                myHandler.removeCallbacks(updateTimerMethod);

            }
        });

    }

    private Runnable updateTimerMethod = new Runnable() {

        public void run() {
            timeInMillies = SystemClock.uptimeMillis() - startTime;
            finalTime = timeSwap + timeInMillies;

            int seconds = (int) (finalTime / 1000);
            int minutes = seconds / 60;
            seconds = seconds % 60;
            int milliseconds = (int) (finalTime % 1000);
            textTimer.setText("" + minutes + ":"
                    + String.format("%02d", seconds) + ":"
                    + String.format("%03d", milliseconds));
            myHandler.postDelayed(this, 0);
        }

    };

}

我的 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"
    android:background="@android:color/white" >
    <Button

    android:id="@+id/btnPause"
    android:layout_width="90dp"
    android:layout_marginLeft="20dp"
    android:layout_height="45dp"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@+id/btnStart"
    android:text="Pauza" />

    <Button
    android:id="@+id/btnStart"
    android:layout_width="90dp"
    android:layout_height="45dp"

    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="68dp"
    android:text="Start" />

    <TextView
    android:id="@+id/textTimer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/btnPause"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="37dp"
    android:textSize="40sp"
    android:textColor="#000000"
    android:text="00:00:00" />

</RelativeLayout>

和我的 AndroidManifest.xml中文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="cz.miegl.stopky"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="cz.miegl.stopky.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

请帮助我。我不知道该做什么。谢谢!

Please help me. I do not know what to do. Thank you!

请救救我!谢谢!

推荐答案

您的activity_main.xml文件的FrameLayout。这是一个占位符,另一种观点认为,和therfore不显示任何内容。通常你会在你使用的片段使用了这一观点。您但是没有使用的片段。

You have a framelayout in your activity_main.xml file. This is a placeholder for another view, and therfore does not show anything. Normally you would use this view when you are using fragments. You are however not using fragments.

既然你是一个初学者复制从fragment_main的全部内容到activity_main.xml文件。

Since you are a beginner copy the entire content from fragment_main into the activity_main.xml file.