3.6 ScrollView

一、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;
            }
        });
    }
}
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页