Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android TabHost内容未显示_Android_Android Tabhost_Android Tabactivity - Fatal编程技术网

Android TabHost内容未显示

Android TabHost内容未显示,android,android-tabhost,android-tabactivity,Android,Android Tabhost,Android Tabactivity,我创建了一个TabHost,并用选项卡分配了4个活动意图,这些似乎工作得很好。我唯一的问题是活动内容没有显示在我的tabhost视图中的framelayout#tabcontent中 我按照官方的参考资料浏览了互联网,寻找解决方案,但我看不出问题出在哪里 Log.v(“活动”、“报告”)记录在ant中,因此它确实执行活动。因此,我猜是我的ReportsActivity中的setContentView()导致了这个问题。但我是新手,所以我真的不知道。(没有生成错误) 这是我的主人 <?xml

我创建了一个TabHost,并用选项卡分配了4个活动意图,这些似乎工作得很好。我唯一的问题是活动内容没有显示在我的tabhost视图中的framelayout#tabcontent中

我按照官方的参考资料浏览了互联网,寻找解决方案,但我看不出问题出在哪里

Log.v(“活动”、“报告”)记录在ant中,因此它确实执行活动。因此,我猜是我的ReportsActivity中的setContentView()导致了这个问题。但我是新手,所以我真的不知道。(没有生成错误)

这是我的主人

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@android:id/tabhost"
    android:background="#FFFFFF">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FFFFFF">

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

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5sp"
            android:layout_weight="1" />

    </LinearLayout>

</TabHost>
这是我的内容活动(R.layout.reports=linearlayout和文本视图)


试着像这样实现您的TabSpec:

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

spec = tabHost.newTabSpec("reports")
              .setIndicator(
                  res.getText(R.string.reports),
                  res.getDrawable(R.drawable.reports))
              .setContent(intent);

这是因为您选择了默认为水平布局的线性布局。
如果在LinearLayout标记内设置android:orientation=“vertical”以解决您的问题

则TabSpec没有方法addFlags,因此我尝试在我的意图中使用该标志,但tabcontent仍不显示我的ReportsActivity LinearLayout。编辑:我的ReportsActivity是否应该扩展默认活动超类以外的任何其他活动?如果我删除xml中的TabWidget,FrameLayout会突然显示活动内容。我尝试使用边距来查看TabWidget是否与FrameLayout重叠,但事实并非如此(我认为)。TabWidget应该与此相关吗?我没有看到,您在tabspec之外初始化了意图。addFlag属于intent。看我的更正答案。是的,我明白了-问题仍然存在。如果我从XML中删除TabWidget元素,framelayout将显示活动内容,但如果我再次实现TabWidget元素,则不会显示活动内容。所以,我猜我的setContentView或tabhost存在问题?结果是,tabhost中的线性布局需要android:orientation=“vertical”,现在一切都正常了。
public class ReportsActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.reports);

        Log.v("Activity", "Reports");
    }
}
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

spec = tabHost.newTabSpec("reports")
              .setIndicator(
                  res.getText(R.string.reports),
                  res.getDrawable(R.drawable.reports))
              .setContent(intent);