0

enter image description herecréer une application onglets avec des vues personnalisées

Je suis confronté au problème sur la conception de cette application, onglets avec des vues personnalisées, où deux onglets sont disponibles la première patte ayant 3 élément, chaque élément ayant 3 sous-élément et chaque sous-élément ayant 3 sous-éléments. Le 2ème onglet je dois montrer l'image avec l'étiquette de l'URL.

Répondre

0
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 


    <TabHost 
     android:id="@+id/tabHost" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

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

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

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

       <RelativeLayout 
        android:id="@+id/first_tab" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 
       //YOUR FIRST VIEW CREATE OR INCLUDE VIEW 
        <include 
        android:id="@+id/first_tab" 
        layout="@layout/first_tab" /> 

       </RelativeLayout> 

       <RelativeLayout 
        android:id="@+id/secend_tab" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        //YOUR SECEND VIEW CREATE OR INCLUDE VIEW 
        <include 
        android:id="@+id/secend_tab" 
        layout="@layout/secend_tab" /> 
       </RelativeLayout> 

      </FrameLayout> 
     </LinearLayout> 
    </TabHost> 
</LinearLayout> 

et le code dans votre activité, de dialogue, etc.

TabHost host = (TabHost) findViewById(R.id.tabHost); 
    host.setup(); 

    //Tab 1 
    TabHost.TabSpec spec = host.newTabSpec("firstTab"); 
    spec.setContent(R.id.first_tab); 
    spec.setIndicator("TABE ONE"); 
    host.addTab(spec); 


    //Tab 2 
    spec = host.newTabSpec("secendTab"); 
    spec.setContent(R.id.secend_tab); 
    spec.setIndicator("TAB TWO"); 
    host.addTab(spec); 
0

Il est simple. Structuré une mise en page en XML pour votre onglet. Gonflez ensuite et appelez

getTabAt(x).setCustomView(View v); 

Le code va comme:

TextView tabOne = (TextView)LayoutInflater.from(this).inflate(R.layout.custom_tab, null); 
    tabOne.setText("ONE"); 
    tabOne.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_tab_favourite, 0, 0); 
    tabLayout.getTabAt(0).setCustomView(tabOne); 
0

tout d'abord créer tablayout pour vos onglets

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabMode="fixed" 
      app:tabGravity="fill"/> 
    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
</android.support.design.widget.CoordinatorLayout> 

http://www.androidhive.info/2015/09/android-material-design-working-with-tabs/

Ensuite, pour votre premier onglet besoin expandablelistview

http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/

+0

est-ce résolu ou pas –