android - ScrollView 中的 TabHost : always scrolls down when a Tab is clicked

标签 android android-tabhost android-scrollview

我有一个 Activity,它有一个 Scrollview 作为顶级元素。里面有一些其他的 View ,在某些时候有一个 TabHost。查看 the screenshot 可能会给您留下更好的印象. TabHost 有三个选项卡,每个选项卡都有另一个由 Intent 启动的 Activity 。

除一件事外,一切正常。每当我单击选项卡时,Scrollview 会自动向下滚动,如您所见 over here . TabHost 之后不在屏幕上。我只是不想让它向下滚动,但看不出问题是什么。我在 1.5 和 1.6 设备以及 2.0 模拟器上进行了测试,结果相同。

我的 TabHost 的 xml 如下所示:

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

这是添加标签的代码:

private void addTab(int descriptionRes, Class<?> destination, int flags) {
    String description = getString(descriptionRes);
    TabSpec spec = mTabHost.newTabSpec(description);
    spec.setIndicator(description);
    Intent i = new Intent(this, destination);
    i.setData(Uri.parse(member.getId())).setFlags(flags);
    spec.setContent(i);
    mTabHost.addTab(spec);
}

有什么建议吗?

最佳答案

您可以尝试将 TabHostActivity inside 设置为可滚动,而不是顶级 Activity本身。

关于android - ScrollView 中的 TabHost : always scrolls down when a Tab is clicked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2014305/

相关文章:

android - 强制导入 R.Java

java - 如何从imageView获取drawable名称

android - Firebase 电子邮件验证未更新状态

android - 当键盘出现时,底部 View 被向上推

java - 如何在没有动画的情况下滚动到 ScrollView 中的某个位置?

android - 为什么 CalendarProvider 不允许写 ExtendedProperties?

android - 选项卡中的图标不显示!!!我应该怎么办?

android - 具有动态内容的动态标签生成

java - 在对话框中使用 TabHost 出现 NullPointerException?怎样做才正确呢?

android - 多行 AutoCompleteTextView 不接受滚动触摸