<RelativeLayout 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.girdlayoutdemo.MainActivity" >
<ProgressBar
android:id="@+id/pb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<GridView
android:layout_below="@id/pb"
android:id="@+id/gv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:gravity="center"
android:numColumns="2" >
</GridView>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/item_iv"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="3" />
<TextView
android:id="@+id/item_tv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
public class MainActivity extends Activity {
private GridView gv;
private ProgressBar pb;
private List<Map<String, Object>> list;
private SimpleAdapter adapter;
private GestureDetector gsDetector;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
pb.setVisibility(View.GONE);
Toast.makeText(MainActivity.this, "刷新成功", 200).show();
break;
default:
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pb = (ProgressBar) findViewById(R.id.pb);
gv = (GridView) findViewById(R.id.gv);
pb.setVisibility(View.GONE);
initData();
adapter = new SimpleAdapter(this, list, R.layout.item_layout,
new String[] { "image", "text" }, new int[] { R.id.item_iv,
R.id.item_tv });
gv.setAdapter(adapter);
gsDetector = new GestureDetector(this, new Mlistener());
gv.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// Log.e("MainActivity", event.getX()+"");
return gsDetector.onTouchEvent(event);
}
});
}
private void initData() {
list = new ArrayList<Map<String, Object>>();
for (int i = 0; i < 20; i++) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("image", R.drawable.gift_item_default);
map.put("text", "一只冰莹猪猪");
list.add(map);
}
}
class Mlistener implements OnGestureListener {
@Override
public boolean onDown(MotionEvent e) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (e2.getY() - e1.getY() > 0 && gv.getFirstVisiblePosition() == 0) {
pb.setVisibility(View.VISIBLE);
Animation animation = new ScaleAnimation(1f, 1f, 0, 1f);
animation.setDuration(300);
pb.startAnimation(animation);
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(2000);
Message msg = new Message();
msg.what = 1;
handler.sendMessage(msg);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
return false;
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pb = (ProgressBar) findViewById(R.id.pb);
gv = (GridView) findViewById(R.id.gv);
pb.setVisibility(View.GONE);
initData();
adapter = new SimpleAdapter(this, list, R.layout.item_layout,
new String[] { "image", "text" }, new int[] { R.id.item_iv,
R.id.item_tv });
gv.setAdapter(adapter);
gsDetector = new GestureDetector(this, new Mlistener());
gv.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// Log.e("MainActivity", event.getX()+"");
return gsDetector.onTouchEvent(event);
}
});
}
class Mlistener implements OnGestureListener {
@Override
public boolean onDown(MotionEvent e) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
return false;
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (e2.getY() - e1.getY() > 0 && gv.getFirstVisiblePosition() == 0) {
pb.setVisibility(View.VISIBLE);
Animation animation = new ScaleAnimation(1f, 1f, 0, 1f);
animation.setDuration(300);
pb.startAnimation(animation);
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(2000);
Message msg = new Message();
msg.what = 1;
handler.sendMessage(msg);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
return false;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有