package com.cnn.scrollviewdemo01;

import android.R.integer;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView; @SuppressLint("ClickableViewAccessibility") public class MainActivity extends Activity {
private TextView textView;
private ScrollView scrollView;
private Button btnUp,btnDown;
int scrollY=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); textView= (TextView) findViewById(R.id.textView1);
textView.setText(getResources().getString(R.string.china_news)); scrollView=(ScrollView) findViewById(R.id.scrollView1);
scrollView.setOnTouchListener(new OnTouchListener() { @Override
public boolean onTouch(View v, MotionEvent event) {
// TODO 自动生成的方法存根
switch (event.getAction()) {
case MotionEvent.ACTION_UP://手指抬起 break; case MotionEvent.ACTION_DOWN://手指落下 break;
case MotionEvent.ACTION_MOVE://手指滑动
if (scrollView.getScaleY()<=0) {//顶部
Log.i("tag", "没有滑动");
}
//textView总高度<=一屏幕的高度+滚动条的滚动距离
if (scrollView.getChildAt(0).getMeasuredHeight()<=
scrollView.getHeight()+scrollView.getScrollY()) {
Log.i("tag", "没有到底部");
textView.append("123111111111111111111111111111111111111111111111111111111");//(getResources().getString(R.string.china_news));
}
break;
}
return false;
}
}); btnUp=(Button) findViewById(R.id.button2);
btnDown=(Button) findViewById(R.id.button1); btnDown.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO 自动生成的方法存根
//scrollY=scrollY+10;
//scrollView.setScrollY(scrollY);
scrollView.scrollBy(0, 20);
}
}); btnUp.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO 自动生成的方法存根
//scrollY=scrollY-10;
//scrollView.setScrollY(scrollY);
scrollView.scrollBy(0, -20);
}
});
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

  

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Up" /> <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Donw" /> <ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" /> </LinearLayout>
</ScrollView> </LinearLayout>

  

最新文章

  1. Unable to create the selected property page. An error occurred while automatically activating bundle net.sourceforge.pmd
  2. Go语言配置与开发环境配置
  3. java 获取获取字符串编码格式
  4. Hibernate常见接口说明
  5. IOS 定位 单例
  6. struts1标签(html:text)
  7. CKEdit( htm编辑器)
  8. Linux新手的最佳包管理器
  9. How to Use Kdiff3 as a 3-way Merge Tool With Mercurial, Git, and Tower.app
  10. 怎么分别javascript写在&lt;head&gt;里还是&lt;body&gt;里面?
  11. 01——Solr学习之全文检索服务系统的基础认识
  12. Windows下USB磁盘开发系列一:枚举系统中U盘的盘符
  13. Final互评------《飞词》---- 拉格朗日2018
  14. POI往word模板中写入数据
  15. unicode utf8 学习记录
  16. 两种定时器 setInterval(一直执行) setTimeout(只执行一次)
  17. FastReport.Net使用:[26]数字格式
  18. Java - 无乱码读写文件
  19. Unity3D usage Experience
  20. 【转】哈希(Hash)与加密(Encrypt)的基本原理、区别及工程应用

热门文章

  1. mysql字符集修改(ubuntu)
  2. java文件对照工具
  3. linux定时备份mysql数据库文件
  4. bzoj4868: [Shoi2017]期末考试(三分法)
  5. Understanding The Complete Story of Postback in ASP.NET
  6. PyCharm基本设置、常用快捷键
  7. POJ 2184 DP
  8. jquery/zepto在插件编写上的几点区别
  9. C++之虚函数表
  10. Django(part2)