3.6 ScrollView

何宏博
2023-12-01

一、ScrollView的使用

<ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"
        >

        <TextView
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@string/content"
            />

    </ScrollView>

二、监听ScrollView的滑动

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



    final ScrollView scrollView = (ScrollView)findViewById(R.id.scrollView);
        textView = (TextView)findViewById(R.id.content);

        scrollView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_MOVE : {

                        //顶部状态
                        if (scrollView.getScaleY() <= 0) {
                            Log.i("Main", "顶部");
                        }
                        //底部状态
                        if (scrollView.getChildAt(0).getMeasuredHeight() <= scrollView.getHeight()+scrollView.getScrollY()) {
                            Log.i("Main", "底部");
                            textView.append(getResources().getText(R.string.content));
                        }
                    }
                    break;
                }
                return false;
            }
        });
    }
}
 类似资料:

相关阅读

相关文章

相关问答