ScrollView

程式碼修行者發表於2015-07-23

縱向 ScrollView
橫向 HorizontalScrollView

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"
        >
        <TextView
            android:textSize="30sp"
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            />
    </ScrollView>

判斷ScrollView到底部

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

        text = (TextView)findViewById(R.id.text);
//        text.setText(getResources().getString(R.string.hello_world));
        text.setText(R.string.hello_world);

        scrollView = (ScrollView)findViewById(R.id.scroll);

        scrollView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()){
                    case MotionEvent.ACTION_MOVE:
                        //滑動到底部
                        if(scrollView.getChildAt(0).getMeasuredHeight() <= scrollView.getHeight() + scrollView.getScrollY()){
                            text.append("aaaaaaaaaaaaaaaaaaaa");
                        }
                        break;
                }
                return false;
            }
        });
    }

其他 設定scrollView x y 軸 scrollTo
遞增遞減 x y 軸 scrollBy

相關文章