Android_scrollview
xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android_scollview.MainActivity" >
<Button
android:id="@+id/up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="up"
/>
<Button
android:id="@+id/down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="down"
/> <ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/scroll1"
android:scrollbars="none">
<!--
ScrollView 的种类:
ScrollView:垂直滚动视图
HorizontalScrollView:水平滚动视图
隐藏ScrollView
(1)标签属性:scrollbars 设置不显示纵向滚动条
(2)代码设置:
setVerticalScrollBarEnabled(false);隐藏纵向ScrollView
setHorizontalSrollBarEnabled(false);隐藏横向ScrollView -->
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text" />
</ScrollView>
</LinearLayout>
main.java
package com.example.android_scollview; 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;
/**
* 应用案例:判断ScrollView何时滑动到底部
* 利用setOnTouchListener
*
*/
public class MainActivity extends Activity implements OnClickListener{ private TextView tv;
private ScrollView scroll;
private Button up;
private Button down; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
up = (Button) findViewById(R.id.up);
down = (Button) findViewById(R.id.down); up.setOnClickListener(this);
down.setOnClickListener(this);
tv = (TextView) findViewById(R.id.text);
scroll = (ScrollView) findViewById(R.id.scroll1);
scroll.setOnTouchListener(new OnTouchListener() { @Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch(event.getAction()){
case MotionEvent.ACTION_MOVE:{
/**
* (1)getScrollY()--滚动条滑动的距离
* (2)getMeasuredHeight--显示的高度加上隐藏的高度
* (3)getHeight
*/
//顶部状态
if(scroll.getScaleY()<=0){
Log.i("Main", "顶部状态");
}
//底部状态
//TextView的总高度<=一屏幕的高度+滚动条滚动的距离
if(scroll.getChildAt(0).getMeasuredHeight()<=scroll.getHeight()+scroll.getY()){
Log.i("Main", "底部状态");
}
break;
} } return false;
}
});
} @Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
/**
* scroll的两种滑动方式:
* scrollTo:以滚动视图起始位置开始计算
* scrollBy:相对前一次的位置,去滚动对应的距离
*/
case R.id.up:{
scroll.scrollBy(0, -30);
break;
}
case R.id.down:{
scroll.scrollBy(0, 30);
break;
}
}
}
}
Android_scrollview的更多相关文章
随机推荐
- AsyncEnumerableExtensions.cs z
public static class Extensions { public static async Task ForEachAsync<T, U>(this IEnumerable& ...
- 方格取数(1)(HDU 1565状压dp)
题意: 给你一个n*n的格子的棋盘,每个格子里面有一个非负数. 从中取出若干个数,使得任意的两个数所在的格子没有公共边,就是说所取的数所在的2个格子不能相邻,并且取出的数的和最大. 分析:直接枚举 ...
- Robotium自动化测试报告生成
使用Robotium进行测试的时候,要想可以导出可视的测试结果,可以使用junitreport来实现junitreport下载地址:https://github.com/jsankey/android ...
- SSH proxy
# for Linux ssh nobody@guoliangwu.com -P 22 -C -N -D 127.0.0.1:6500 # for windows(PuTTY) plink nobod ...
- 【原创】lua的module的一些点
lua的module好像是5.1开始有的 在xx.lua的开头写上 module('my_module') 这行等价于如下几行 local name = 'my_module' local M = { ...
- dataStructure@ Check if a directed graph has cycles
#include<iostream> #include<cstdio> #include<cstring> #include<limits> #incl ...
- HDU4276 - The Ghost Blows Light(树形DP)
题目大意 给定一棵n个结点的树,每个结点上有一定数量的treasure,经过每条边需要花一定的时间,要求你从结点1出发,在不超过时间T的情况下,最多能够获得的treasure是多少,并且要求结束于结点 ...
- Linux下如何保持gnome-terminal窗口执行命令后停留而不立刻关闭(gnome-terminal -x)
Linux下如何保持gnome-terminal窗口执行命令后停留而不立刻关闭(gnome-terminal -x) 转自:http://jakfruit.blog.163.com/blog/stat ...
- 跟着Android官网学习Activity
1.Activity介绍 An Activity is an application component that provides a screen with which users can int ...
- hdu 1491 Octorber 21st
Octorber 21st Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...