这是效果
主要是onTouchListener监听事件,监视什么时候滑到底部
同时要理解getMeasuredHeight和getHeight的区别
getMeasuredHeight:全部的长度 包括隐藏的
getHeight:在布局中展示出来的长度
布局文件:
MainActivity
package com.example.scrollview; import android.opengl.Visibility; import android.os.Bundle; import android.app.Activity; import android.support.v4.app.NotificationCompat.Action; import android.util.Log; import android.view.Menu; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnTouchListener; import android.view.Window; import android.widget.Button; import android.widget.ScrollView; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { private ScrollView scroll; private TextView text; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); scroll=(ScrollView) findViewById(R.id.scrollview); text=(TextView) findViewById(R.id.text); button=(Button) findViewById(R.id.next); text.setText(getResources().getString(R.string.lyric)); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub text.append(getResources().getString(R.string.lyric)); button.setVisibility(View.INVISIBLE); } }); scroll.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub switch(event.getAction()){ case MotionEvent.ACTION_MOVE:{ break; } case MotionEvent.ACTION_DOWN:{ break; } case MotionEvent.ACTION_UP:{ //当文本的measureheight 等于scroll滚动的长度+scroll的height if(scroll.getChildAt(0).getMeasuredHeight()<=scroll.getScrollY()+scroll.getHeight()){ button.setVisibility(View.VISIBLE); }else{ } break; } } return false; } }); } }
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!