1


正如我在標題中所指出的,我已經在ActionBar中實現了Sherlock和Tab導航。標籤是碎片。在一個片段裏面我有一個mapView。當我在選項卡之間切換時遇到一些問題。兩個選項卡只是列表,其中一個是MapView和其他一些視圖,另一個是一些設置信息。
我的問題是,當我改變標籤我得到一些閃爍......這只是足夠長的時間來捕捉它的眼睛。這是當我在常規標籤中移動,但是當我首先進入一個mapview選項卡時,我會看到一個持續時間更長,然後閃爍的黑屏。
有人有這個問題或一些類似的問題?
編輯的代碼:
Sherlock,Fragments,Tabs和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 

     } 

    } 
+0

你的執行情況如何?讓我們來看看。 – Moesio 2013-03-20 19:17:00

回答

0

的「黑視」,這聽起來像你所描述的是一個已知問題的片段,其中之一是V2地圖之間切換時。你可以在this post中閱讀更多關於它的信息。我自己也遇到過這個問題。在引用的帖子中提出的解決方案非常簡單。

<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> 

在透明黑色視圖中添加視圖可消除此問題。不知道爲什麼,但確實如此。

+0

但我沒有ViewPager在我的應用程序...碎片不是在視圖尋呼機...只是選項卡...我編輯了一些代碼的問題... – Jovan 2013-03-21 09:19:27

+0

您是否驗證地圖問題是不相關的其實它是一個片段?我不確定黑匣子問題是否與視圖尋呼機特定相關。我會看看你發佈的代碼,看看我能想到什麼。 – Rarw 2013-03-21 15:52:05

+0

谷歌地圖是MapView ...因爲在該片段中我有一個Map和一些其他佈局(一些列表視圖,一些按鈕和一個搜索視圖)... – Jovan 2013-03-21 16:04:20