Froyo 中的选项卡布局问题

发布于 2024-11-17 17:27:15 字数 3654 浏览 2 评论 0原文

我创建了一个基于选项卡的应用程序,在其中一个选项卡中,还有一个内部选项卡,其中一些数据使用适配器以表格格式显示。在所有 Android 2.1 设备上都完全没问题。但在所有配备 Android 2.2 的设备中,它仅显示第一个选项卡,且上方为黑屏。我给出了两张不同的截图供参考。

2.1 设备屏幕截图

2.1 设备屏幕截图

2.2 设备屏幕截图

2.2 设备的屏幕截图

tabactivity 的 XML

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:id="@+id/myinfotrackerlayout"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"/>
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:gravity="bottom" 
            android:isScrollContainer="false" 
            android:scrollbarAlwaysDrawHorizontalTrack="false" 
            android:scrollbarAlwaysDrawVerticalTrack="false" 
            android:scrollbars="none"
            android:background="#FFFFFF"/>
    </LinearLayout>
</TabHost>

Tabactivity 的代码

public class MyInfoTracker extends TabActivity {
    private int tabid = 0;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.myinfotracker);
        try{
            final TabHost innerTabHost = getTabHost();  // The activity TabHost
            TabHost.TabSpec spec;  // Resusable TabSpec for each tab

            Intent intent;  // Reusable Intent for each tab
            Intent myint = this.getIntent();
            tabid = myint.getIntExtra("tab_id", 0);

            // Create an Intent to launch an Activity for the tab (to be reused) 
            intent = new Intent().setClass(this, MyinfoActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
            intent.putExtra("addType","CD4");

            // Initialize a TabSpec for each tab and add it to the TabHost
            spec = innerTabHost.newTabSpec("CD4Count").setIndicator("CD4 Count").setContent(intent);
            innerTabHost.addTab(spec);

            // Do the same for the other tabs
            intent = new Intent().setClass(this, MyinfoActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
            intent.putExtra("addType","VL");
            spec = innerTabHost.newTabSpec("ViralLoad").setIndicator("Viral Load").setContent(intent);
            innerTabHost.addTab(spec);

            // Do the same for the other tabs
            intent = new Intent().setClass(this, MyinfoActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
            intent.putExtra("addType","Wt");
            spec = innerTabHost.newTabSpec("Weight").setIndicator("Weight").setContent(intent);
            innerTabHost.addTab(spec);

            innerTabHost.setScrollbarFadingEnabled(false);
            innerTabHost.setScrollContainer(false);

            innerTabHost.setCurrentTab(tabid);
        }catch(Exception e){}
    }
}

什么可能导致此类问题?

I have created a tab based app, in one of the tab, there is also inner tab where some data is displayed in tabular format using adapter. It is perfectly ok in all devices with Android 2.1. But in all the devices with Android 2.2 devices, it is just showing only first tab only with black screen above. I have given two different screenshot for the reference.

Screenshot of 2.1 device

Screenshot of 2.1 device

Screenshot of 2.2 device

Screenshot of 2.2 device

XML for tabactivity

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:id="@+id/myinfotrackerlayout"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"/>
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:gravity="bottom" 
            android:isScrollContainer="false" 
            android:scrollbarAlwaysDrawHorizontalTrack="false" 
            android:scrollbarAlwaysDrawVerticalTrack="false" 
            android:scrollbars="none"
            android:background="#FFFFFF"/>
    </LinearLayout>
</TabHost>

Code for Tabactivity

public class MyInfoTracker extends TabActivity {
    private int tabid = 0;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.myinfotracker);
        try{
            final TabHost innerTabHost = getTabHost();  // The activity TabHost
            TabHost.TabSpec spec;  // Resusable TabSpec for each tab

            Intent intent;  // Reusable Intent for each tab
            Intent myint = this.getIntent();
            tabid = myint.getIntExtra("tab_id", 0);

            // Create an Intent to launch an Activity for the tab (to be reused) 
            intent = new Intent().setClass(this, MyinfoActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
            intent.putExtra("addType","CD4");

            // Initialize a TabSpec for each tab and add it to the TabHost
            spec = innerTabHost.newTabSpec("CD4Count").setIndicator("CD4 Count").setContent(intent);
            innerTabHost.addTab(spec);

            // Do the same for the other tabs
            intent = new Intent().setClass(this, MyinfoActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
            intent.putExtra("addType","VL");
            spec = innerTabHost.newTabSpec("ViralLoad").setIndicator("Viral Load").setContent(intent);
            innerTabHost.addTab(spec);

            // Do the same for the other tabs
            intent = new Intent().setClass(this, MyinfoActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );
            intent.putExtra("addType","Wt");
            spec = innerTabHost.newTabSpec("Weight").setIndicator("Weight").setContent(intent);
            innerTabHost.addTab(spec);

            innerTabHost.setScrollbarFadingEnabled(false);
            innerTabHost.setScrollContainer(false);

            innerTabHost.setCurrentTab(tabid);
        }catch(Exception e){}
    }
}

What may cause this type of problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蝶…霜飞 2024-11-24 17:27:15

这根本不是选项卡相关的问题。在 onCreate() 中有一段代码 -

datePickerDialog = new DatePickerDialog(getParent(), ButtonTestDateListener,
                mYear, mMonth, mDay);

我刚刚将 mYearmMonthmDay 声明为 Integer,但没有初始化。它在 2.1 中工作正常,但在 2.2 中给出问题。这就是为什么它会出现这样的问题。

It is not at all tab related prob. In onCreate() there is a code-

datePickerDialog = new DatePickerDialog(getParent(), ButtonTestDateListener,
                mYear, mMonth, mDay);

I have just declare the mYear, mMonth and mDay as Integer, but no initialization was there. It is working fine in 2.1, but giving prob in 2.2. Thats why it is giving such problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文