正如我在標題中所指出的,我已經在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
}
}
你的執行情況如何?讓我們來看看。 – Moesio 2013-03-20 19:17:00