2010-11-26 82 views
0

我正在爲android編寫一個應用程序,需要選項卡,並且我的列表中的內容滾動到了我的選項卡上。我知道這一定很簡單,但我找不到它。Android:內容滾動選項卡

這裏是我的main.xml

<TabWidget android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:id="@android:id/tabs" /> 

<FrameLayout android:layout_width="fill_parent" 
    android:layout_height="fill_parent" android:id="@android:id/tabcontent"> 

</FrameLayout> 

這裏是Java代碼

公共類再次擴展TabActivity { @覆蓋 公共無效的onCreate( Bundle savedInstanceState){ super.onCreate(s avedInstanceState); setContentView(R.layout.main);

Resources res = getResources(); // Resource object to get Drawables 
    TabHost tabHost = getTabHost(); // The activity TabHost 
    TabHost.TabSpec spec; // Resusable TabSpec for each tab 
    Intent intent; // Reusable Intent for each tab 

    // Create an Intent to launch an Activity for the tab (to be reused) 
    intent = new Intent().setClass(this, Download.class); 

    // Initialize a TabSpec for each tab and add it to the TabHost 
    spec = tabHost.newTabSpec("download") 
      .setIndicator("", res.getDrawable(R.drawable.ok)) 
      .setContent(intent); 
    tabHost.addTab(spec); 

    // Do the same for the other tabs 
    intent = new Intent().setClass(this, Settings.class); 
    spec = tabHost.newTabSpec("settings") 
      .setIndicator("", res.getDrawable(R.drawable.ok)) 
      .setContent(intent); 
    tabHost.addTab(spec); 

    tabHost.setCurrentTab(0); 
} 

}

任何幫助將不勝感激。

傑森

+1

是否有什麼原因讓您對tabactivity調用setContentView?你一般不應該那樣做。這幾乎肯定是因爲你的framelayout設置爲fill_parent。你不需要一個tabactivity的視圖,它在內部都有。 – Falmarri 2010-11-26 04:53:38

回答

0

感謝您尋找,但我只是理解了它。對於那些和我一樣愚蠢的人來說,如果main.xml沒有正確設置,那麼內容不知道該去哪裏。我討厭如此模糊,但我一直在搞它,直到它工作,並不能給你一個比這更好的答案。這是新的main.xml,如果你想看看它。

   <LinearLayout 
        android:id="@+layout/tab2" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" /> 
      </FrameLayout> 
     </LinearLayout> 

好運編碼傢伙。

更高版本

相關問題