我有一个 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);
}
有什么建议吗?
最佳答案
您可以尝试将 TabHost
的 Activity
inside 设置为可滚动,而不是顶级 Activity
本身。
关于android - ScrollView 中的 TabHost : always scrolls down when a Tab is clicked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2014305/