2011-05-29 20 views
0

我在我的Android應用程序中調用新的活動:安卓:黑屏,而不是新的活動

Intent intent = new Intent(); 
intent.setClass(getApplicationContext(), UserInfo.class); 
startActivity(intent); 

在新的活動我打電話的setContentView像往常一樣:

public void OnCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.userfill); 

但是我只看到黑色畫面與標題中的活動標籤!

Manifect文件包含

<activity 
    android:name=".UserInfo" 
    android:label="@string/title_fill"> 
</activity> 

userfill.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" android:id="@+id/MainLinearLayout"> 
    <TableLayout android:layout_height="wrap_content" android:id="@+id/tableLayout" android:layout_width="match_parent"> 
     <TableRow android:layout_height="wrap_content" android:id="@+id/tableRow1" android:layout_weight="1" android:layout_width="match_parent"> 
      <AutoCompleteTextView android:layout_height="70dip" android:text="@string/enterTeg" android:id="@+id/autoCompleteTextView1" android:layout_width="match_parent"></AutoCompleteTextView> 
     </TableRow> 
     <TableRow android:layout_height="wrap_content" android:id="@+id/tableRow2" android:layout_weight="1" android:layout_width="match_parent"> 
      <AutoCompleteTextView android:layout_height="70dip" android:layout_width="match_parent" android:text="@string/enterTeg" android:id="@+id/autoCompleteTextView2"></AutoCompleteTextView> 
     </TableRow> 
     <TableRow android:layout_height="wrap_content" android:id="@+id/tableRow3" android:layout_weight="1" android:layout_width="match_parent"> 
      <AutoCompleteTextView android:layout_height="70dip" android:layout_width="match_parent" android:text="@string/enterTeg" android:id="@+id/autoCompleteTextView3"></AutoCompleteTextView> 
     </TableRow> 
     <TableRow android:layout_height="wrap_content" android:id="@+id/tableRow4" android:layout_width="wrap_content" android:layout_weight="1"> 
      <ListView android:layout_height="wrap_content" android:id="@+id/listTimes" android:layout_width="match_parent"></ListView> 
     </TableRow> 
     <TableRow android:id="@+id/tableRow5" android:layout_height="match_parent" android:layout_weight="1" android:layout_width="match_parent" android:orientation="horizontal"> 
      <Button android:id="@+id/button1" android:layout_height="wrap_content" android:text="@string/btnOK" android:layout_weight="1" android:layout_width="150dip"></Button> 
      <Button android:id="@+id/button2" android:layout_height="wrap_content" android:text="@string/btn_cancel" android:layout_weight="0" android:layout_width="160dip"></Button> 
     </TableRow> 
    </TableLayout> 
</LinearLayout> 

爲什麼我沒有看到所有的控件在圖形佈局它的所有權利?

回答

5

onCreate - 方法名稱以小寫開頭。

此外,這是不必要的TableRow定義layout_widthlayout_height

一個TableLayout的孩子不能 指定layout_width屬性。 寬度始終爲MATCH_PARENT。但是, layout_height屬性可以由子項定義的 ;默認值是 WRAP_CONTENT。如果孩子是 TableRow,那麼高度始終爲 WRAP_CONTENT。

請參閱here

+5

因此,您應該始終添加@override表示法,以確保您的函數名中沒有拼寫錯誤。 – matsjoe 2011-05-29 18:55:03

0

在表格的佈局,而不是WRAP_CONTENT,嘗試match_parent