Java 滚动视图中的TabHost在内容更改时滚动
我有一个Java 滚动视图中的TabHost在内容更改时滚动,java,android,scrollview,android-tabhost,Java,Android,Scrollview,Android Tabhost,我有一个滚动视图作为家长。内部有一个LinearLayout,带有ImageView和TabHost。我通过活动更改选项卡host的内容。更改内容时,Tabhost向下滚动到自己的选项卡,标题不再可见。我怎样才能防止这种情况 My main.xml: <?xml version="1.0" encoding="utf-8"?> <ScrollView android:id="@+id/mainScroll" xmlns:android="http://sche
滚动视图
作为家长。内部有一个LinearLayout
,带有ImageView
和TabHost
。我通过活动更改选项卡host
的内容。更改内容时,Tabhost
向下滚动到自己的选项卡,标题不再可见。我怎样才能防止这种情况
My main.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="@+id/mainScroll"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal" >
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="800px"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >
<ImageView
android:id="@+id/header"
android:layout_width="800px"
android:layout_height="200px"
android:src="@drawable/header" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="50px" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
</ScrollView>
我怎样才能避免这种滚动呢?我在另一个类似的地方发布了答案。基本上,我扩展了ScrollView并重写了ComputesCrollDeltaTogetChildReconScreen
不需要滚动的原因是,默认情况下,在requestChildFocus
ScrollView中,滚动到焦点视图(例如TabHost)ComputesCrollDeltaToGetChildReconScreen
用于计算增量滚动以使视图可见
爪哇:
XML:
public class UeberActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ueber);
}
}
public class MyScrollView extends ScrollView {
public MyScrollView(Context context) {
super(context);
}
public MyScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) {
// This function calculates the scroll delta to bring the focused view on screen.
// -> To prevent unsolicited scrolling to the focued view we'll just return 0 here.
//
return 0;
}
}
<YOUR.PAKAGE.NAME.MyScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
</YOUR.PAKAGE.NAME.MyScrollView>