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的更多相关文章
随机推荐
- [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.4.5
Suppose it is known that $\scrM$ is an invariant subspace for $A$. What invariant subspaces for $A\o ...
- [Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.2.10
(1). The numerical radius defines a norm on $\scrL(\scrH)$. (2). $w(UAU^*)=w(A)$ for all $U\in \U(n) ...
- FFmpeg 2.0编译配置
./configure --enable-shared --enable-doc --enable-ffmpeg --enable-ffplay --enable-ffprobe --enable- ...
- Action 操作
当鼠标移动到图片文件夹的时候,将有一些button显示 当鼠标移开这个文件夹,那些button隐藏了起来 display属性的变化 1.可以使用Js改变属性来操作 暂未验证,待时间. 2.可以使用Ac ...
- js 中&& 与 ||
/*** 几乎所有语言中||和&&都遵循“短路”原理,* 如&&中第一个表达式为假就不会去处理第二个表达式,而||正好相反.* js也遵循上述原则.* 当||时,找到为 ...
- 初涉C#防止黑客攻击站短
一.同一个IP如果在一分钟内连续发送5个站短可以认为是不正确的,原因有2方面: 1.发站短的页面是有点击按钮,点击按钮后马上按钮会变为不可点击,所以在前端要防止点击一次触发多次的情况 2.发送短信的U ...
- leetcode Pow(doubule x,int n)
今天第一天开通博客,心情还是小激动的 上代码: 方法一:常规递归,x的n次方={xn/2*xn/2 //n为偶 xn/2*xn/2 *x //n为奇数 } ...
- NOIP2013 货车运输
3.货车运输 (truck.cpp/c/pas) [问题描述] A 国有 n 座城市,编号从 1 到 n,城市之间有 m 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 q 辆货车在运输货 ...
- 【转载】如何在C语言中调用shell命令
转载自:http://blog.csdn.net/chdhust/article/details/7951576 如何在C语言中调用shell命令 在linux操作系统中,很多shell命令使用起来非 ...
- Bzoj-2818 Gcd 欧拉函数
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2818 题意:给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x ...