2010-11-26 83 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> 

好运编码家伙。

更高版本

相关问题