问题描述
我写一个使用许多片段的应用程序。我已经使用ActionBarSherlock(与动作条)。要绕的bug#,我已经决定要在功能上工作实现切换到使用ActionBarSherlock是 TabHost 。
工作半年了几个小时后,工作正常,除非我的页面之间的刷卡:该记者选项卡中选择,但不集中,经常连不可见,所以用户不能看选择哪个选项卡。
I am writing an app that uses many fragments. I have used ActionBarSherlock (with ActionBar). To work-around bug #240, I've decided to switch a functionally working implementation to use ActionBarSherlock with TabHost.After half a few hours of work, it is working fine, except for when I am swiping between pages: The correspondent tab is selected, but is not centered and often not even visible so the user can't see which tab is selected.
在画面可以看到明显的片段(WEEKLY秒。),但该选项卡的只有一半可见。接下来的刷卡只会让WEEKLY小号......看起来像日历事件,我不知道哪个选项卡中选择,除非我手动刷卡TabWidget。
In the picture you can see the visible fragment ("WEEKLY S..") but the tab is only half visible. The next swipe will only make "WEEKLY S..." look like "CALENDAR EVENTS" and I won't know which Tab is selected unless I swipe the TabWidget manually.
下面是我的activity_main.xml中:
Here is my activity_main.xml:
<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">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tabStripEnabled="true"
android:orientation="horizontal" />
</HorizontalScrollView>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0"/>
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</TabHost>
和我TabsAdapter是一样的杰克沃顿例子href=\"https://github.com/JakeWharton/ActionBarSherlock/blob/master/actionbarsherlock-samples/fragments/src/com/actionbarsherlock/sample/fragments/FragmentTabsPager.java\"相对=nofollow> FragmentTabsPager 。
And my TabsAdapter is the same as Jake Wharton's example of FragmentTabsPager.
任何建议,欢迎!
推荐答案
由于这个post,并,我设法得到它的工作。这里是code:
Thanks to this post, and to jucas in particular, I managed to get it to work. Here is the code:
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
View tabView = mTabHost.getTabWidget().getChildAt(position);
if (tabView != null)
{
final int width = mHorizontalScroll.getWidth();
final int scrollPos = tabView.getLeft() - (width - tabView.getWidth()) / 2;
mHorizontalScroll.scrollTo(scrollPos, 0);
} else {
mHorizontalScroll.scrollBy(positionOffsetPixels, 0);
}
}
当然,我不得不 mHorizontalScroll
在几个地方进行初始化。 (如果有人不知道如何做到这一点,我会很高兴张贴满code)
Of course I had to get mHorizontalScroll
initialized in several places. (If someone isn't sure how to do it, I'll be happy to post the full code.)
这篇关于TabHost标签使用ViewPager刷卡时不水平滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!