2012-12-05 62 views
0

我覺得我的問題很簡單,所以謝謝你的幫助。我做了一個簡單的遊戲,終於運行了,但是我不能讓開始內容顯示在頁面,任何人都可以幫我解決這個問題嗎?如何在中心顯示遊戲開始頁面

這是目前頁:

請輸入這裏看rendering 代碼:

RES /佈局/ activity.xml

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout 
     android:background="@color/background" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="horizontal" 
     xmlns:android="http://schemas.android.com/apk/res/android"> 
     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_gravity="center"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:textSize="25sp" 
       android:textColor="#7ba6df" 
       android:text="@string/activity_main_title"/> 
      <Button 
       android:id="@+id/continue_button" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/continue_lable"/> 
      <Button 
       android:id="@+id/new_button" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/new_game_lable"/> 
      <Button 
       android:id="@+id/about_button" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/about_lable"/> 
      <Button 
       android:id="@+id/exit_button" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/exit_lable"/> 
     </LinearLayout> 
    </LinearLayout> 

RES /價值/ string.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <string name="activity_main_title">android sudoku</string> 
    <string name="continue_lable">開始遊戲</string> 
    <string name="about_lable">遊戲說明</string> 
    <string name="new_game_lable">是否開啓音樂</string> 
    <string name="exit_lable">退出遊戲</string> 

</resources> 

Mainactivity.java

public class MainActivity extends Activity { 

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

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.activity_main, menu); 
     return true; 
    } 

} 
+0

申請layout_gravity =中心 –

回答

0

這會爲你工作:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/background" 
    android:gravity="center" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="@string/activity_main_title" 
      android:textColor="#7ba6df" 
      android:textSize="25sp" /> 

     <Button 
      android:id="@+id/continue_button" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/continue_lable" /> 

     <Button 
      android:id="@+id/new_button" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/new_game_lable" /> 

     <Button 
      android:id="@+id/about_button" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/about_lable" /> 

     <Button 
      android:id="@+id/exit_button" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/exit_lable" /> 
    </LinearLayout> 

</LinearLayout> 
0

試試這個修改XML

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout 
     android:background="@color/background" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:gravity="center_horizontal|center_vertical" 
     xmlns:android="http://schemas.android.com/apk/res/android"> 
     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical|center_horizontal"> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:textSize="25sp" 
       android:textColor="#7ba6df" 
       android:text="@string/activity_main_title"/> 
      <Button 
       android:id="@+id/continue_button" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/continue_lable"/> 
      <Button 
       android:id="@+id/new_button" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/new_game_lable"/> 
      <Button 
       android:id="@+id/about_button" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/about_lable"/> 
      <Button 
       android:id="@+id/exit_button" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/exit_lable"/> 
     </LinearLayout> 
    </LinearLayout> 
0

三個選項,你可以添加到佈局代碼

1.

android:gravity="center_vertical|center_horizontal" 

2.

android:centerInParent="true" 

3.

android:layout_centerHorizontal="true" 
android:layout_centerVertical="true"