0

我有一个NavigationDrawer,可以在单击按钮时打开片段。但现在,我需要在这些片段之一中制作一个Tabhost。我从来没有使用过TabHost,也找不到任何解释如何在片段内的一个TabHost中实现Swipe效果的主题。在此之前,我已经配置了Tabhost,但没有任何效果。如果你能解释我该怎么做,我会很感激。在片段内的TabHost中滑动效果

PacksFragment.java

package studio.com.archeagemanager; 


import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.TabHost; 
import android.widget.TextView; 

/** 
* A simple {@link Fragment} subclass. 
*/ 


public class PacksFragment extends Fragment { 

    TabHost tabHost; 

    public PacksFragment() { 
     // Required empty public constructor 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     View view = inflater.inflate(R.layout.fragment_packs, container, false); 

     TabHost host = (TabHost) view.findViewById(R.id.tabhost); 
     host.setup(); 

     //Tab 1 
     TabHost.TabSpec spec = host.newTabSpec("Tab One"); 
     spec.setContent(R.id.nuia); 
     spec.setIndicator("NUIA"); 
     host.addTab(spec); 

     //Tab 2 
     spec = host.newTabSpec("Tab two"); 
     spec.setContent(R.id.haranya); 
     spec.setIndicator("HARANYA"); 
     host.addTab(spec); 

     //Tab 3 
     spec = host.newTabSpec("Tab three"); 
     spec.setContent(R.id.oceanic); 
     spec.setIndicator("OCEANIC"); 
     host.addTab(spec); 

     //Tab 4 
     spec = host.newTabSpec("Tab four"); 
     spec.setContent(R.id.auroria); 
     spec.setIndicator("AURORIA"); 
     host.addTab(spec); 

     for (int i=0; i<4; i++) { 
      View tabView = host.getTabWidget().getChildTabViewAt(i); 
      tabView.setPadding(0, 0, 0, 0); 
      TextView tv = (TextView)tabView.findViewById(android.R.id.title); 
      tv.setSingleLine(); 
      tv.setTextSize(14); 
     } 

     return view; 
    } 

} 

回答

0

在布局文件fragments_pack只是水平滚动查看按您的要求类似添加标签主机后,对该

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@android:id/tabhost" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="5dp"> 

    <HorizontalScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/horizontalScrollView" 
     android:fillViewport="true" 
     android:scrollbars="none"> 

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

    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="5dp" /> 
</LinearLayout>