SlowScrollView用法大全
来源:互联网 发布:三国杀陈琳淘宝 编辑:程序博客网 时间:2024/05/01 02:07
public class SlowScrollView extends ScrollView {
public SlowScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public SlowScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SlowScrollView(Context context) {
super(context);
}
/**
* 滑动事件
*/
@Override
public void fling(int velocityY) {
super.fling(velocityY / 4);
}
}
代码说明:
重点在"velocityY / 4",这里意思是滑动速度减慢到原来四分之一的速度,这里大家可以根据自己的需求加快或减慢滑动速度。
ScrollView(滚动视图)是实现滚动的一个控件,只需要将需要滚动的控件添加到ScrollView中即可!ScrollView可以在代码中进行设置,也可以在XML布局文件中进行设置!
1.Activity文件如下:
import android.app.Activity;
import android.os.Bundle;
import android.widget.ScrollView;
import android.widget.TextView;
public class ScrollViewActivity extends Activity {
}
}
- <?xml version="1.0" encoding="utf-8"?>
- <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/ScrollView" android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:scrollbars="vertical">
- <LinearLayout android:id="@+id/LinearLayout"
- android:orientation="vertical" android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- <TextView android:id="@+id/TestView" android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:text="TestView0" />
- <Button android:id="@+id/Button" android:text="Button0" android:layout_width="fill_parent"
- android:layout_height="wrap_content"></Button>
- </LinearLayout>
- </ScrollView>
<?xml version="1.0" encoding="utf-8"?><ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ScrollView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbars="vertical"> <LinearLayout android:id="@+id/LinearLayout" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/TestView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="TestView0" /> <Button android:id="@+id/Button" android:text="Button0" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button> </LinearLayout></ScrollView>
- package com.Aina.Android;
- import android.app.Activity;
- import android.os.Bundle;
- import android.os.Handler;
- import android.view.KeyEvent;
- import android.view.View;
- import android.widget.Button;
- import android.widget.LinearLayout;
- import android.widget.ScrollView;
- import android.widget.TextView;
- publicclass Test_ScrollViewextends Activity {
- /** Called when the activity is first created. */
- private LinearLayout mLayout;
- private ScrollView sView;
- privatefinal Handler mHandler =new Handler();
- @Override
- publicvoid onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- // 创建一个线性布局
- mLayout = (LinearLayout) this.findViewById(R.id.LinearLayout);
- // 创建一个ScrollView对象
- sView = (ScrollView) this.findViewById(R.id.ScrollView);
- Button mBtn = (Button) this.findViewById(R.id.Button);
- mBtn.setOnClickListener(mClickListener);// 添加点击事件监听
- }
- publicboolean onKeyDown(int keyCode, KeyEvent event){
- Button b = (Button) this.getCurrentFocus();
- int count = mLayout.getChildCount();
- Button bm = (Button) mLayout.getChildAt(count-1);
- if(keyCode==KeyEvent.KEYCODE_DPAD_UP && b.getId()==R.id.Button){
- bm.requestFocus();
- returntrue;
- }elseif(keyCode==KeyEvent.KEYCODE_DPAD_DOWN && b.getId()==bm.getId()){
- this.findViewById(R.id.Button).requestFocus();
- returntrue;
- }
- returnfalse;
- }
- // Button事件监听,当点击第一个按钮时增加一个button和一个textview
- private Button.OnClickListener mClickListener =new Button.OnClickListener() {
- privateint index =1;
- @Override
- publicvoid onClick(View v) {
- TextView tView = new TextView(Test_ScrollView.this);//定义一个TextView
- tView.setText("TextView" + index);//设置TextView的文本信息
- //设置线性布局的属性
- LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.FILL_PARENT,
- LinearLayout.LayoutParams.WRAP_CONTENT);
- mLayout.addView(tView, params);//添加一个TextView控件
- Button button = new Button(Test_ScrollView.this);//定义一个Button
- button.setText("Button" + index);//设置Button的文本信息
- button.setId(index++);
- mLayout.addView(button, params);//添加一个Button控件
- mHandler.post(mScrollToButton);//传递一个消息进行滚动
- }
- };
- private Runnable mScrollToButton =new Runnable() {
- @Override
- publicvoid run() {
- int off = mLayout.getMeasuredHeight() - sView.getHeight();
- if (off >0) {
- sView.scrollTo(0, off);//改变滚动条的位置
- }
- }
- }; }
- SlowScrollView用法大全
- vi用法大全!
- COOKIE用法大全
- ajax用法大全
- ajax用法大全
- const用法大全
- #pragma用法大全
- #pragma用法大全
- dpkg用法大全
- request的用法大全
- #pragma用法大全
- Shutdown用法大全
- ListView基本用法大全
- Hints用法大全
- js 用法大全
- #pragma用法大全
- #pragma用法大全
- 星号的用法大全
- Tomcat 配置 https 协议
- CocosBuilder工具使用(包仔的个人经验)
- java二维码生成与解析代码实现
- 数字101的特别之处
- spring 依赖对象的注入方式(3种) 和 公共属性的设置abstract="true" parent
- SlowScrollView用法大全
- ArcGIS API for Silverlight之ElementLayer使用注意点
- CPU卡中T=0通讯协议的分析与实现
- C#(asp.net)上传视频转换为flv格式并给视频截图代码
- Objective-C 2.0 新特性介绍
- js浮点数计算错误的bug
- SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
- HTTP状态码
- writeToFile写入不成功的原因