Android FragmentTabHost问题
我觉得Android FragmentTabHost的文档记录很差,所以我试图理解这个问题的基本内容 1关于代码段: 1.1它显示了添加选项卡的编程方法。我能避免吗?我可以用XML定义所有内容吗:选项卡的数量、标签、内容(指向同样用XML定义的片段布局的链接)?如果不是,为什么?因为部分通过静态XML以编程方式定义应用程序布局看起来像是一种黑客行为(尽管定义本身也是静态的) 1.2此代码段是否暗示任何XML布局文件?有官方的例子吗 1.3假设这段代码确实暗示了一个XML布局文件:什么是realtabcontent和tabcontent?我应该两者都要吗?为什么?看起来又像是黑客攻击 2这里是一个使用FragmentTabHost的非官方示例 2.1为什么应将LinearLayout放在android.support.v4.app.FragmentTabHost中?是否有官方文件对此作出解释 2.2为什么LinearLayout只包含一个FrameLayout,而不是像这里这样的两个?为什么我们不需要@+id/realtabcontent和@android:id/tabs?为什么这里将Android FragmentTabHost问题,android,android-layout,android-fragments,fragment-tab-host,Android,Android Layout,Android Fragments,Fragment Tab Host,我觉得Android FragmentTabHost的文档记录很差,所以我试图理解这个问题的基本内容 1关于代码段: 1.1它显示了添加选项卡的编程方法。我能避免吗?我可以用XML定义所有内容吗:选项卡的数量、标签、内容(指向同样用XML定义的片段布局的链接)?如果不是,为什么?因为部分通过静态XML以编程方式定义应用程序布局看起来像是一种黑客行为(尽管定义本身也是静态的) 1.2此代码段是否暗示任何XML布局文件?有官方的例子吗 1.3假设这段代码确实暗示了一个XML布局文件:什么是realt
android:id=“@+id/realtabcontent”
更改为android:id=“@+android:id/realtabcontent”
很重要?您可以看到
import com.example.android.supportv4.R;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
/**
* This demonstrates how you can implement switching between the tabs of a
* TabHost through fragments, using FragmentTabHost.
*/
public class FragmentTabs extends FragmentActivity {
private FragmentTabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_tabs);
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
FragmentStackSupport.CountingFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"),
LoaderCursorSupport.CursorLoaderListFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"),
LoaderCustomSupport.AppListFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"),
LoaderThrottleSupport.ThrottledLoaderListFragment.class, null);
}
}