3

私はScrollView親として持っています。中にはLinearLayoutと がImageViewありTabHostます。TabHostvia アクティビティのコンテンツを変更します。コンテンツを変更すると、Tabhost独自のタブまでスクロールダウンし、ヘッダーが表示されなくなります。どうすればこれを防ぐことができますか?

私の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>

コンテンツを変更するマイ アクティビティ:

    public class UeberActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ueber);
    }
}

このスクロールを回避するにはどうすればよいですか?

4

1 に答える 1

1

回答を投稿した別の同様の質問がありました。基本的に ScrollView を拡張して上書きしcomputeScrollDeltaToGetChildRectOnScreenました。

不要なスクロールの理由は、requestChildFocusScrollView ではデフォルトでフォーカスされたビュー (TabHost など) にスクロールするためです。computeScrollDeltaToGetChildRectOnScreenビューを表示するためのデルタスクロールを計算するために使用されます。

ジャワ:

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;
    }
}

XML:

<YOUR.PAKAGE.NAME.MyScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
</YOUR.PAKAGE.NAME.MyScrollView>
于 2016-09-14T13:25:12.340 に答える