Android 滑动效果代码分享
2011-06-04 09:29
363 查看
ORIETech - Mobile Application Development
package com.ScrollListView;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.AbsListView.OnScrollListener;
publicclass EndLessActivity extends ListActivity implements OnScrollListener {
Aleph0 adapter =new Aleph0();
int mProgressStatus =0;
ProgressBar progressBar;
protectedvoid onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout searchLayout =new LinearLayout(this);
searchLayout.setOrientation(LinearLayout.HORIZONTAL);
progressBar =new ProgressBar(this);
progressBar.setPadding(0, 0, 15, 0);
searchLayout.addView(progressBar,new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
));
TextView textView =new TextView(this);
textView.setText("加载中...");
textView.setGravity(Gravity.CENTER_VERTICAL);
searchLayout.addView(textView,new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT
));
searchLayout.setGravity(Gravity.CENTER);
LinearLayout loadingLayout =new LinearLayout(this);
loadingLayout.addView(searchLayout,new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
));
loadingLayout.setGravity(Gravity.CENTER);
getListView().addFooterView(loadingLayout);
setListAdapter(adapter);
getListView().setOnScrollListener(this);
}
publicvoid onScroll(AbsListView
view,
int firstVisible, int visibleCount, int totalCount) {
boolean loadMore =/* maybe
add a padding */
firstVisible + visibleCount >= totalCount;
if(loadMore) {
adapter.count += visibleCount; // or
any other amount
adapter.notifyDataSetChanged();
}
}
publicvoid onScrollStateChanged(AbsListView
v, int s) { }
class Aleph0 extends BaseAdapter {
int count =40; /* starting amount */
publicint getCount() { return count; }
public Object getItem(int pos) { return pos; }
publiclong getItemId(int pos) { return pos; }
public View getView(int pos, View v, ViewGroup p) {
TextView view =new TextView(EndLessActivity.this);
view.setText("entry "+ pos);
return view;
}
}
}
listview下部是按钮控制:
package com.ScrollListView;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.AbsListView.OnScrollListener;
publicclass EndLessActivity extends ListActivity {
Aleph0 adapter =new Aleph0();
int mProgressStatus =0;
protectedvoid onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout searchLayout =new LinearLayout(this);
searchLayout.setOrientation(LinearLayout.HORIZONTAL);
Button textView =new Button(this);
textView.setText("加载中...");
textView.setGravity(Gravity.CENTER_VERTICAL);
searchLayout.addView(textView,new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT
));
searchLayout.setGravity(Gravity.CENTER);
LinearLayout loadingLayout =new LinearLayout(this);
loadingLayout.addView(searchLayout,new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
));
loadingLayout.setGravity(Gravity.CENTER);
getListView().addFooterView(loadingLayout);
textView.setOnClickListener(new Button.OnClickListener()
{ @Override
publicvoid onClick(View v)
{
adapter.count +=10;
adapter.notifyDataSetChanged();
}
});
setListAdapter(adapter);
//getListView().setOnScrollListener(this);
}
/*public void onScroll(AbsListView view,
int firstVisible, int visibleCount, int totalCount) {
boolean loadMore =
firstVisible + visibleCount >= totalCount;
if(loadMore) {
adapter.count += visibleCount;
adapter.notifyDataSetChanged();
}
} */
publicvoid onScrollStateChanged(AbsListView
v, int s) { }
class Aleph0 extends BaseAdapter {
int count =40; /* starting amount */
publicint getCount() { return count; }
public Object getItem(int pos) { return pos; }
publiclong getItemId(int pos) { return pos; }
public View getView(int pos, View v, ViewGroup p) {
TextView view =new TextView(EndLessActivity.this);
view.setText("entry "+ pos);
return view;
}
}
}
package com.ScrollListView;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.AbsListView.OnScrollListener;
publicclass EndLessActivity extends ListActivity implements OnScrollListener {
Aleph0 adapter =new Aleph0();
int mProgressStatus =0;
ProgressBar progressBar;
protectedvoid onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout searchLayout =new LinearLayout(this);
searchLayout.setOrientation(LinearLayout.HORIZONTAL);
progressBar =new ProgressBar(this);
progressBar.setPadding(0, 0, 15, 0);
searchLayout.addView(progressBar,new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
));
TextView textView =new TextView(this);
textView.setText("加载中...");
textView.setGravity(Gravity.CENTER_VERTICAL);
searchLayout.addView(textView,new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT
));
searchLayout.setGravity(Gravity.CENTER);
LinearLayout loadingLayout =new LinearLayout(this);
loadingLayout.addView(searchLayout,new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
));
loadingLayout.setGravity(Gravity.CENTER);
getListView().addFooterView(loadingLayout);
setListAdapter(adapter);
getListView().setOnScrollListener(this);
}
publicvoid onScroll(AbsListView
view,
int firstVisible, int visibleCount, int totalCount) {
boolean loadMore =/* maybe
add a padding */
firstVisible + visibleCount >= totalCount;
if(loadMore) {
adapter.count += visibleCount; // or
any other amount
adapter.notifyDataSetChanged();
}
}
publicvoid onScrollStateChanged(AbsListView
v, int s) { }
class Aleph0 extends BaseAdapter {
int count =40; /* starting amount */
publicint getCount() { return count; }
public Object getItem(int pos) { return pos; }
publiclong getItemId(int pos) { return pos; }
public View getView(int pos, View v, ViewGroup p) {
TextView view =new TextView(EndLessActivity.this);
view.setText("entry "+ pos);
return view;
}
}
}
listview下部是按钮控制:
package com.ScrollListView;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.AbsListView.OnScrollListener;
publicclass EndLessActivity extends ListActivity {
Aleph0 adapter =new Aleph0();
int mProgressStatus =0;
protectedvoid onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout searchLayout =new LinearLayout(this);
searchLayout.setOrientation(LinearLayout.HORIZONTAL);
Button textView =new Button(this);
textView.setText("加载中...");
textView.setGravity(Gravity.CENTER_VERTICAL);
searchLayout.addView(textView,new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT
));
searchLayout.setGravity(Gravity.CENTER);
LinearLayout loadingLayout =new LinearLayout(this);
loadingLayout.addView(searchLayout,new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
));
loadingLayout.setGravity(Gravity.CENTER);
getListView().addFooterView(loadingLayout);
textView.setOnClickListener(new Button.OnClickListener()
{ @Override
publicvoid onClick(View v)
{
adapter.count +=10;
adapter.notifyDataSetChanged();
}
});
setListAdapter(adapter);
//getListView().setOnScrollListener(this);
}
/*public void onScroll(AbsListView view,
int firstVisible, int visibleCount, int totalCount) {
boolean loadMore =
firstVisible + visibleCount >= totalCount;
if(loadMore) {
adapter.count += visibleCount;
adapter.notifyDataSetChanged();
}
} */
publicvoid onScrollStateChanged(AbsListView
v, int s) { }
class Aleph0 extends BaseAdapter {
int count =40; /* starting amount */
publicint getCount() { return count; }
public Object getItem(int pos) { return pos; }
publiclong getItemId(int pos) { return pos; }
public View getView(int pos, View v, ViewGroup p) {
TextView view =new TextView(EndLessActivity.this);
view.setText("entry "+ pos);
return view;
}
}
}
相关文章推荐
- Android开发之ViewPager结合Fragment实现滑动页面的效果(源代码分享)
- Android 利用ViewPager实现图片可以左右循环滑动效果附代码下载
- Android中View跟随手指滑动效果的实例代码
- Android 滑动定位和吸附悬停效果实现代码
- Android 拖拽效果实现代码分享 - ORIETech
- Android实现仿通讯录侧边栏滑动SiderBar效果代码
- jquery左右全屏大尺寸多图滑动效果代码分享
- jquery左右全屏大尺寸多图滑动效果代码分享
- Android中轮播所用到viewPager.PageTransformer 页面滑动时候处理图片缩放效果代码
- Android 仿ios 可滑动切换效果按钮 实例代码
- Android自定义滑动删除效果的实现代码
- js滑动提示效果代码分享
- Android应用中制作选中后图标变大浮动效果的代码分享
- Android view滑动悬浮固定效果实现代码示例
- Android 自定义 HorizontalScrollView 打造多图片OOM 的横向滑动效果(实例代码)
- Android ImageButton自定义按钮的按下效果的代码实现方法分享
- Android开发之ViewPager滑动页面效果实现(源代码分享)
- 分享一个自已写的仿iphone手机滑动效果的JS代码....
- android ViewPager实现滑动翻页效果实例代码
- js滑动提示效果代码分享