2014-06-08 37 views
0

我正在使用水平滚动视图,但标签不滑动仅内容更改。请帮帮我。当我翻页时,标签不会翻转。水平滚动视图为tabwiget不滑动标签

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

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 
      <FrameLayout 
       android:id="@+id/tab1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:visibility="gone" /> 
      <FrameLayout 
       android:id="@+id/tab2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:visibility="gone" /> 

//

TabWidget tw = (TabWidget) rootView.findViewById(android.R.id.tabs); 
LinearLayout ll = (LinearLayout) tw.getParent(); 
HorizontalScrollView hs = new HorizontalScrollView(getActivity()); 
hs.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT)); 
ll.addView(hs, 0); 
ll.removeView(tw); 
hs.addView(tw); 
hs.setHorizontalScrollBarEnabled(false); 
hs.setFillViewport(true); 

当我翻动页面,然后标签不轻弹。

+0

http://chat.stackoverflow.com/rooms/70243/farsi-programming-discussion – Kasramvd

回答

0

你需要使用我认为的TabHost。 在This Link你可以找到30多个使用TabHost和TabWidget的例子看看我的示例布局,你也应该根据例子改变你的代码。 也有很好的简单的例子:http://www.learn-android-easily.com/2013/07/android-tabwidget-example.html

<TabHost 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     > 
     <TabWidget 
     android:id="@android:id/tabs" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     > 
    </TabWidget> 

    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 
     <FrameLayout 
      android:id="@+id/tab1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:visibility="gone" /> 
     <FrameLayout 
      android:id="@+id/tab2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:visibility="gone" /> 
      . 
      . 
      . 
    </LinearLayout> 
</TabHost>