0

我正在编写一个 android 游戏,我为具有以下 XML 的主菜单创建了一个布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tvStats"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="fill_horizontal"
        android:gravity="fill_horizontal" >

        <Button
            android:id="@+id/btnStartSurvive"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="fill_horizontal"
            android:gravity="center_vertical|center_horizontal"
            android:text="Start Survival Mode" />

        <Button
            android:id="@+id/btnStartChall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="fill_horizontal"
            android:text="Start Callenge Mode" />

    </LinearLayout>

</LinearLayout>

使用此活动在屏幕上显示布局:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.*;

public class MainActivity extends Activity {


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

        //Get rid of the stuff around the edges
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        //show layout
        setContentView(R.layout.main_menu);
        Button btnStart = (Button)findViewById(R.id.btnStartSurvive);
        btnStart.setOnClickListener(oclStart);
    }

    private OnClickListener oclStart = new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(MainActivity.this, GameActivity.class);
            intent.putExtra("gametype", 'S');
            startActivity(intent);  
        }
    };

}

当我在手机(Android 4.2.2)上运行它时,我得到如下所示的东西:

图 1

单击未使用的按钮使其看起来像这样:

图 1

当我在我的旧平板电脑(Android 2.2)上运行它时,我得到了我的预期:

图 3

这是一个Android错误吗?我该如何解决?

还是我的错?我如何解决它?

4

1 回答 1

0

我设法在运行 4.2.2 的 Galaxy s4 上复制了相同的结果。由于某种原因,按钮似乎不能很好地工作。

您是否尝试过更改主题?有时主题会弄乱布局。

于 2013-08-06T02:25:48.310 回答