40

Il layout grafico per un semplice android.support.v4.app.FragmentTabHost non viene mai visualizzato in Eclipse o Android Studio.
errore La console che ottengo è costantemente:
Exception raised during rendering: No tab known for tag nullFragmentTabHost layout grafico non renderizzato

Sto usando il file XML di base:

<android.support.v4.app.FragmentTabHost 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:orientation="horizontal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0"/> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="0dp" 
      android:layout_height="0dp" 
      android:layout_weight="0"/> 

     <FrameLayout 
      android:id="@+id/realtabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1"/> 

    </LinearLayout> 
</android.support.v4.app.FragmentTabHost> 

ma si verifica lo stesso errore.

Volevo solo aggiungere più viste sopra o sotto il widget scheda e il layout della cornice.
Non mi interessa molto vedere il contenuto della scheda; Voglio solo vedere il resto del mio layout - ma il problema è che NESSUN ALTRO VISUALIZZA viene eseguito quando unoandroid.support.v4.app.FragmentTabHostrisiede nel layout.

ho letto e ho cercato di risolvere il problema della risposta a questo post:
Android: Tabs at the bottom with FragmentTabHost
ma non credo che questo è il mio problema; Non sto cercando di mettere un TabWidget sul fondo.

Ogni altro file XML si apre perfettamente.

Lo stesso problema si verifica in Android Studio:
Android Studio doesn't render this either

+0

È l'errore logcat o console? Se logcat, per favore posta. – anthropomo

+0

è un log degli errori: in eclissi: (Eccezione sollevata durante il rendering: nessuna scheda nota per il tag null Dettagli dell'eccezione vengono registrati in Finestra> Mostra vista> Registro errori) – lory105

+3

FragmentTabHost non mostrerà alcun contenuto in quanto il contenuto verrà aggiunto dinamicamente . Quindi nessun problema loro. Dovrebbe funzionare quando aggiungi le schede nel codice e provalo. http://www.androidhive.info/2011/08/android-tab-layout-tutorial/ – mipreamble

risposta

0

non è sicuro .... ma non dovrebbe avere il layout di un tag tabhost in esso sopra il layout lineare del TabWidget?

<TabHost 
    android:id="@+id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/background" 
> 

ho fatto un app un po 'indietro che le schede che utilizzano tabhost implented e questo è come la mia disposizione era ... una scheda aveva una vista del diario uno aveva uno switcher di immagine e uno aveva un listview ... mi dispiace non può essere di maggiore aiuto

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/background" 
tools:context=".MainActivity" > 

<TabHost 
    android:id="@+id/tabhost" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/background" 
> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/background" 
     android:orientation="vertical" > 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

     </TabWidget> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <LinearLayout 
       android:id="@+id/tab1" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" > 

       <ListView 
        android:id="@+id/listView1" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" > 
       </ListView> 
      </LinearLayout> 

      <LinearLayout 
       android:id="@+id/tab2" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" > 

       <ImageSwitcher 
        android:id="@+id/imageSwitcher1" 
        android:layout_width="match_parent" 
        android:layout_height="251dp" > 
       </ImageSwitcher> 

       <TextView 
        android:id="@+id/tv" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:scrollbars="vertical" /> 

      </LinearLayout> 

      <LinearLayout 
       android:id="@+id/tab3" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" > 

       <CalendarView 
        android:id="@+id/calendarView1" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" /> 
      </LinearLayout> 

     </FrameLayout> 
    </LinearLayout> 

</TabHost> 

+2

Beh, un normale android.widget.TabHost funzionerebbe, eccetto che [android.app.TabActivity è deprecato] [tabasticity] a favore dell'utilizzo di FragmentTabHosts e Fragments. [Tabactivity]: [http://developer.android.com/reference/android/app/TabActivity.html] – EricRobertBrewer

1

non è sicuro circa l'errore che hai (mi dispiace, io sono molto occupato in questo momento quindi non si può spendere più tempo a controllare), ma in generale sembra che il FragmentTabHost dalle librerie di supporto non si preoccupi affatto dell'XML. Vedere la mia risposta precedente a un'altra domanda:

FragmentTabHost with horizontal scroll

1

Da layout sto ottenendo lo stesso Error..so, ho risolvere quel problema Codice solo ... Si sta lavorando fine..Please provare questo codice

import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.support.v4.app.FragmentTabHost; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 

public class DetailFragment extends Fragment { 

    /****************************************************************************************************************** 
    * Mandatory empty constructor for the fragment manager to instantiate the fragment (e.g. upon screen orientation changes). 
    *****************************************************************************************************************/ 
    public DetailFragment() { 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     // R.layout.fragment_tabs_pager contains the layout as specified in your question 
     View rootView = inflater.inflate(R.layout.fragment_tabs_pager, container, false); 

     // Initialise the tab-host 
     FragmentTabHost mTabHost = (FragmentTabHost) rootView.findViewById(R.id.tabhost); 
     mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent); 

     // Initialise this list somewhere with the content that should be displayed 
     List<String> itemsToBeDisplayed; 

     for (String subItem : itemsToBeDisplayed) { 
      // Give along the name - you can use this to hand over an ID for example 
      Bundle b = new Bundle(); 
      b.putString("TAB_ITEM_NAME", subItem); 

      // Add a tab to the tabHost 
      mTabHost.addTab(mTabHost.newTabSpec(subItem).setIndicator(subItem), YourContentFragment.class, b); 
     } 
     return rootView; 
    } 
} 



/******************************************************** 
This class contains the actual content of a single tab 
**********************************************************/ 
public class YourContentFragment extends Fragment { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     Bundle extras = getArguments(); 
     if (extras != null) { 
      if (extras.containsKey("TAB_ITEM_NAME")) { 
       String subItem = extras.getString("TAB_ITEM_NAME"); 
       // Do something with that string 
      } 
     } 
    } 
} 
1

se u bisogno di mettere le schede frammentati sul fondo dello schermo ... @fallow sottoelencati -

Fai il file XML come questo ..

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <!-- <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> android:layout_alignParentTop="true" --> 

     <FrameLayout 
      android:id="@+id/realtabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="0dip" 
      android:layout_weight="1" /> 


     <android.support.v4.app.FragmentTabHost 
      android:id="@android:id/tabhost" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      > 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="0dip" 
       android:layout_height="0dip" 
       android:layout_weight="0" /> 

     </android.support.v4.app.FragmentTabHost> 

    </LinearLayout> 

Ora se la vostra preoccupazione è l'apertura di diversi frammenti con in singole schede frammentate ...

@follow passi ::

  1. Creare un frammento del contenitore. Questo frammento del contenitore sarà predefinito per tutti i contenuti delle tue schede.
  2. Per ogni contenuto della scheda sostituire il frammento U necessario con questo contenitore.

Per esempio: - Come si sostituisce il letto con diverse lenzuola .. :)

vostro contenitore classe frammento che verrà utilizzata in modo diverso in diverse schede ... "LearnContainerFragment.java"

public class LearnContainerFragment extends BaseContainerFragment { 

     private boolean mIsViewInited; 

     @Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
      Log.e("test", "tab 1 oncreateview"); 
      return inflater.inflate(R.layout.container_fragment, null); 
     } 

     @Override 
     public void onActivityCreated(Bundle savedInstanceState) { 
      super.onActivityCreated(savedInstanceState); 
      Log.e("test", "tab 1 container on activity created"); 
      if (!mIsViewInited) { 
       mIsViewInited = true; 
       initView(); 
      } 
     } 

     private void initView() { 
      Log.e("test", "tab 1 init view"); 
      replaceFragment(new Learn(), false); 
     } 

    } 

LearnContainerFragment.java ---> è file xml container_fragment.xml

<?xml version="1.0" encoding="utf-8"?> 
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/container_framelayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 


    </FrameLayout> 

@ Come usare Cona tiner ..

  1. Per ogni frammento U necessario verrà sostituito con l'id di questo frammento contenitore.

@Last tua classe BaseContainerFragment.java -

public class BaseContainerFragment extends Fragment { 

    public void replaceFragment(Fragment fragment, boolean addToBackStack) { 
     FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); 
     if (addToBackStack) { 
      transaction.addToBackStack(null); 
     } 
     transaction.replace(R.id.container_framelayout, fragment); 
     transaction.commit(); 
     getChildFragmentManager().executePendingTransactions(); 
    } 

    public boolean popFragment() { 
     Log.e("test", "pop fragment: " + getChildFragmentManager().getBackStackEntryCount()); 
     boolean isPop = false; 
     if (getChildFragmentManager().getBackStackEntryCount() > 0) { 
      isPop = true; 
      getChildFragmentManager().popBackStack(); 
     } 
     return isPop; 
    } 

} 

speriamo vi sia utile ..... Cheers!

4

Ho avuto lo stesso problema di rendering e errore di compilazione. Ho risolto il problema scoprendo che non stavo passando Fragment quando stavo creando Addtab. Devi passare almeno un frammento su mTabHost.addTab. Di seguito è riportato il codice di lavoro.

private FragmentTabHost mTabHost; 
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost); 
      mTabHost.setup(HomeActivity.this, getSupportFragmentManager(), android.R.id.tabcontent); 

      mTabHost.addTab(mTabHost.newTabSpec("home").setIndicator("Home"), HomeFragment.class, null); 
      mTabHost.addTab(mTabHost.newTabSpec("mysheets").setIndicator("MySheets")); 
      mTabHost.addTab(mTabHost.newTabSpec("bookmarks").setIndicator("Bookmarks")); 
Problemi correlati