1


正如我在标题中指出的那样,我已经在里面实现了 ActionBar Sherlock 和 Tab 导航。标签是片段。在一个片段中,我有一个 mapView。我在标签之间切换时遇到了一些问题。两个选项卡只是列表,其中一个是带有其他视图的 MapView,另一个带有一些设置信息。
我的问题是,当我更改标签时,我会出现一些闪烁......它的长度足以用眼睛捕捉它。这是我在常规选项卡中移动的时候,但是当我首先进入 mapview 选项卡时,我得到一个黑屏,持续时间长一点,然后闪烁。
有人有这个问题或类似的问题吗???
编辑代码:

@Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        //setContentView(R.layout.sherlock);
        Log.i(TAG, "onCreate");
        settings_drawable = new StateListDrawable();
        settings_drawable.addState(new int [] {STATE_PRESSED}, getResources().getDrawable(R.drawable.jk_uma_button_settings_pressed));
        settings_drawable.addState(new int[] {}, getResources().getDrawable(R.drawable.jk_uma_button_settings_normal));

        home = new StateListDrawable();
        home.addState(new int [] {STATE_PRESSED}, getResources().getDrawable(R.drawable.jk_button_home_pressed));
        home.addState(new int[] {}, getResources().getDrawable(R.drawable.jk_button_home_normal));

        bar = getSupportActionBar();


        bar.setDisplayShowTitleEnabled(false);
        bar.setIcon(R.drawable.jk_uma_logo);

        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        bar.setHomeButtonEnabled(true);

        tabs_adapter = new TabAdapter(this);

        tabs_adapter.addTab(bar.newTab().setText(" Home").setIcon(R.drawable.jk_icon_home), "Tab1", MapHome.class, null);
        tabs_adapter.addTab(bar.newTab().setText(" Explore").setIcon(R.drawable.jk_icon_explore), "Tab2", MapExplore.class, null);
        tabs_adapter.addTab(bar.newTab().setText(" My Views").setIcon(R.drawable.jk_icon_myview), "Tab3", MapMyStreams.class, null);
    }

public static class TabAdapter implements ActionBar.TabListener {

        private final Context context;
        private final ActionBar action_bar;
        private final HashMap<String, TabInfo> tabs = new HashMap<String, TabInfo>();
        private TabInfo last_tab = null;
        private TabInfo camera_info;

        private String current_camera_tab;
        private String current_fragment_tab;

        private class TabInfo {
            private String tag;
            private Class clss;
            private Bundle args;
            private Fragment fragment;
            private Fragment fragment_details;
            private String current_fragment;

            TabInfo(String tag, Class clazz, Bundle args, String curent) {
                this.tag = tag;
                this.clss = clazz;
                this.args = args;
                this.current_fragment = curent;
            }

        }

        public TabAdapter(SherlockFragmentActivity activity) {
            super();
            this.context = activity;
            this.action_bar = activity.getSupportActionBar();
        }

        public void addTab(ActionBar.Tab tab, String tag, Class<?> clss, Bundle args){
            Log.i(((Sherlock)context).TAG, "addTab");
            TabInfo info = new TabInfo(tag, clss, args, "1");
            tab.setTag(tag);
            tab.setTabListener(this);
            tabs.put(tag, info);
            action_bar.addTab(tab);
        }

        Handler h = new Handler(){
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                switchTab(String.valueOf(msg.obj));
            }
        };

        public void changeOnRuntime(String camera_no){
            Log.i("TABS ADAPTER", "=================changeOnRuntime========="+camera_no);
            Bundle args = new Bundle();
            args.putString("camera_no", camera_no);
            FragmentTransaction ft = ((Sherlock)context).getSupportFragmentManager().beginTransaction();

            String tag = (String) action_bar.getSelectedTab().getTag();
            TabInfo tab = tabs.get(tag);
                Fragment fragm = MapCamera.newInstance(camera_no);
                tab.fragment_details = fragm;
                tab.current_fragment = "2";
                ft.hide(tab.fragment);
                ft.add(android.R.id.content, tab.fragment_details, "Tab5");

            ft.commit();
        }

        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            Log.i("TAB SELECTED", "===================NOT NULL=============="+ ft);
            if(ft == null){
                Log.i("TAB SELECTED", "===================NULLLLLLLLLLLL==============");
            }
            String tag = (String) tab.getTag();
            TabInfo newTab = (TabInfo) this.tabs.get(tag);
            if (last_tab != newTab) {

                    if (newTab != null) {
                        Log.i("TAB SELECTED", "===================NEW TAB==============");

                        if(newTab.current_fragment.equalsIgnoreCase("1")){
                            Log.i("TAB SELECTED", "===================NEW TAB 1==============");
                            if (newTab.fragment == null) {
                                Log.i("TAB SELECTED", "===================NEW TAB 1 NULL==============");
                                newTab.fragment = Fragment.instantiate(context,
                                        newTab.clss.getName(), newTab.args);
                                ft.add(android.R.id.content, newTab.fragment, newTab.tag);
                            }else {
                                Log.i("TAB SELECTED", "===================NEW TAB 1 NOT NULL==============");
                                ft.attach(newTab.fragment);
                            }
                        }else{
                            Log.i("TAB SELECTED", "===================NEW TAB 2==============");
                            ft.attach(newTab.fragment_details);
                        }


                    }
                    last_tab = newTab;
                    }                               
            }
        }

        public void switchTab(String tab){
            if(tab.equalsIgnoreCase("Tab1")){
                action_bar.setSelectedNavigationItem(0);
            }else if (tab.equalsIgnoreCase("Tab2")) {
                action_bar.setSelectedNavigationItem(1);
            }else if (tab.equalsIgnoreCase("Tab4")) {
                action_bar.setSelectedNavigationItem(3);
            }
        }

        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            Log.i("TAB SELECTED", "=================== 2222 ==============");
            if (last_tab != null) {
                if (last_tab.fragment != null) {
                    if(last_tab.current_fragment.equalsIgnoreCase("1")){
                        Log.i("TAB SELECTED", "=================== detach 1 ==============");
                        ft.detach(last_tab.fragment);
                    }else{
                        Log.i("TAB SELECTED", "=================== detach 2 ==============");
                        ft.detach(last_tab.fragment_details);
                    }

                }
            }
        }

        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }

    }
4

1 回答 1

0

听起来您所描述的“黑色视图”是在片段之间切换时的一个已知问题,其中之一是 v2 地图。您可以在这篇文章中阅读更多相关信息。我自己也遇到过这个问题。引用帖子中提出的解决方案非常简单。

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<android.support.v4.view.ViewPager
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>

<!-- hack to fix ugly black artefact with maps v2 -->
<FrameLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="@android:color/transparent" />

</FrameLayout> 

在透明的黑色视图上添加视图可以解决此问题。不知道为什么,但确实如此。

于 2013-03-20T20:08:50.283 回答