Tab小部件无法正确显示onResume()

时间:2011-12-28 16:05:47

标签: android layoutparams android-windowmanager clipped

我正在使用自定义TabWidget来显示我的标签。当我第一次运行程序时,选项卡运行得非常好。一切看起来都很美。但是,当我重新加载程序时,根据logcat,在我的Tab Widget上调用onResume()方法,TabWidget只显示小部件的上半部分。这是我的TabWidget的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" >

    <RelativeLayout
        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_above="@android:id/tabs"/>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="55dp"
            android:layout_alignParentBottom="true" />

    </RelativeLayout>

</TabHost>

这里的香草很简单。更改layout_height没有帮助。

我目前没有在我的TabWidget.java中实现onResume。但无论如何,仍然是代码。

public class TabWidget extends TabActivity {

    private TabHost mTabHost;

    private void setupTabHost() {
        mTabHost = (TabHost) findViewById(android.R.id.tabhost);
        mTabHost.setup();
    }

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.tabs);

        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); // The
                                                                        // activity
                                                                        // TabHost

        TabHost.TabSpec spec; // Resusable TabSpec for each tab
        Intent intent; // Reusable Intent for each tab

        setupTabHost();
        // mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);

        // Dealer tab
        Intent intentDealer = new Intent().setClass(this, DealerActivity.class);
        int iconDealer = (R.drawable.ic_tab_dealer);
        setupTab("Dealer", intentDealer, iconDealer);

        // Department tab
        Intent intentDept = new Intent().setClass(this, DeptActivity.class);
        int iconDept = R.drawable.ic_tab_dept;
        setupTab("Departments", intentDept, iconDept);

        // PostBoard Activity
        Intent intentBoard = new Intent().setClass(this, BoardActivity.class);
        int iconBoard = R.drawable.ic_tab_board;
        setupTab("Postboard", intentBoard, iconBoard);

        // Social Network connection
        // Check first to see if there are Social Network links if not don't
        // show tab.
        if (Startup.msMain.locations[Startup.nChosenLocation].social_media_feeds.length == 0) {

        } else {
            Intent intentSocial = new Intent().setClass(this,
                    SocialActivity.class);
            int iconSocial = R.drawable.ic_tab_social;
            setupTab("Social Media", intentSocial, iconSocial);
        }

        // Links Activity
        Intent intentLinks = new Intent().setClass(this, LinksActivity.class);
        int iconLinks = R.drawable.ic_tab_link;
        setupTab("Links", intentLinks, iconLinks);

        // set startup tab
        tabHost.setCurrentTab(0);
    }

    private void setupTab(final String tag, Intent intent, int img) {
        View tabview = createTabView(mTabHost.getContext(), tag, img);

        TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview)
                .setContent(intent);

        mTabHost.addTab(setContent);

    }

    private static View createTabView(final Context context, final String text,
            int img) {
        View view = LayoutInflater.from(context)
                .inflate(R.layout.tabs_bg, null);
        TextView tv = (TextView) view.findViewById(R.id.tabsText);
        tv.setText(text);
        ImageView icon = (ImageView) view.findViewById(R.id.tabsIcon);
        icon.setBackgroundDrawable(context.getResources().getDrawable(img));
        return view;
    }
}

为了彻底,这里出现错误时我的logcat。

   12-28 10:10:00.963: I/ActivityManager(1305): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.zocalolabs.demo/.SplashScreen } from pid 1470
   12-28 10:10:01.034: W/InputManagerService(1305): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@40777988 (uid=10001 pid=1470)
   12-28 10:10:01.073: I/ActivityManager(1305): Resumed Activity: com.zocalolabs.demo/.TabWidget totalTime: 110 ms

有没有办法强制我的窗口小部件活动重绘onResume()或onPause()强制它完全杀死Activity,从而再次强制它到onCreate方法?或者有另一种方法可以解决这个问题吗?感谢您的任何见解!

1 个答案:

答案 0 :(得分:2)

问题在于

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

正在剪切活动视图的底部。我不知道这是一个bug还是什么,但修复是添加以下行。

   getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
            WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

希望这有助于其他人。