ScrollView滚动条
滚动到底部:fullScroll()方法:
scrollView.fullScroll(ScrollView.FOCUS_DOWN);滚动到底部
scrollView.fullScroll(ScrollView.FOCUS_UP);滚动到顶部
使用按钮滚动
public class MainActivity extends AppCompatActivity implements View.OnClickListener { private Button btn_down; private Button btn_up; private ScrollView scrollView; private TextView txt_show; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bindViews(); } private void bindViews() { btn_down = (Button) findViewById(R.id.btn_down); btn_up = (Button) findViewById(R.id.btn_up); scrollView = (ScrollView) findViewById(R.id.scrollView); txt_show = (TextView) findViewById(R.id.txt_show); btn_down.setOnClickListener(this); btn_up.setOnClickListener(this); StringBuilder sb = new StringBuilder(); for (int i = 1; i <= 100; i++) { sb.append("呵呵 * " + i + " "); } txt_show.setText(sb.toString()); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_down: scrollView.fullScroll(ScrollView.FOCUS_DOWN); break; case R.id.btn_up: scrollView.fullScroll(ScrollView.FOCUS_UP); break; } } }
(代码参考菜鸟教程)