效果



用法


package com.cd.slidetest;import android.os.Bundle;import android.app.Activity;import android.graphics.Color;import android.view.GestureDetector;import android.view.Menu;import android.view.MotionEvent;import android.view.GestureDetector.SimpleOnGestureListener;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.ScrollView;public class MainActivity extends Activity implements OnScrollChangedListener{private GestureDetector mGestureDetector = null;private HScrollView mItemRoom = null;private ScrollView mVertical = null;private HScrollView mTimeItem = null;private LinearLayout mContain = null;@SuppressWarnings("deprecation")@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);mGestureDetector = new GestureDetector(mGestureListener);makeItems();setContentView(mContain);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {getMenuInflater().inflate(R.menu.main, menu);return true;}private void makeItems(){mItemRoom = new HScrollView(this, mGestureDetector);mItemRoom.setListener(this);LinearLayout VLayout = new LinearLayout(this);VLayout.setOrientation(LinearLayout.VERTICAL);for(int i = 0;i < 20;i++){LinearLayout HLayout = new LinearLayout(this);for(int j = 0;j < 10;j++){TextItem item = new TextItem(this);item.setText(i*10+j + "vh");item.setBackgroundColor(Color.LTGRAY);LinearLayout.LayoutParams params = new LayoutParams(100,70);HLayout.addView(item, params);}VLayout.addView(HLayout);}mItemRoom.addView(VLayout);mVertical = new ScrollView(this);LinearLayout hlayout = new LinearLayout(this);LinearLayout vlayout = new LinearLayout(this);vlayout.setOrientation(LinearLayout.VERTICAL);for(int i = 0;i < 20;i++){TextItem item = new TextItem(this);item.setBackgroundColor(Color.BLUE);item.setText(i + "v");LinearLayout.LayoutParams params = new LayoutParams(100,70);vlayout.addView(item, params);}hlayout.addView(vlayout);hlayout.addView(mItemRoom);mVertical.addView(hlayout);LinearLayout tophlayout = new LinearLayout(this);mTimeItem = new HScrollView(this, mGestureDetector);mTimeItem.setListener(this);LinearLayout layout = new LinearLayout(this);for(int i = 0;i < 10;i++){TextItem item = new TextItem(this);item.setText(i + "h");item.setBackgroundColor(Color.GREEN);LinearLayout.LayoutParams params = new LayoutParams(100,70);layout.addView(item,params);}mTimeItem.addView(layout);TextItem item = new TextItem(this);item.setBackgroundColor(Color.RED);LinearLayout.LayoutParams params = new LayoutParams(100,70);tophlayout.addView(item,params);tophlayout.addView(mTimeItem);mContain = new LinearLayout(this);mContain.setOrientation(LinearLayout.VERTICAL);mContain.addView(tophlayout);mContain.addView(mVertical);}private SimpleOnGestureListener mGestureListener = new SimpleOnGestureListener(){@Overridepublic boolean onScroll(MotionEvent e1, MotionEvent e2,float distanceX, float distanceY) {if(Math.abs(distanceX) > Math.abs(distanceY)) {                return true;}return false;}};@Overridepublic void onScrollChanged(HScrollView scroll, int x, int y, int oldx,int oldy) {if(scroll == mItemRoom){mTimeItem.scrollTo(x, y);}else if(scroll == mTimeItem){mItemRoom.scrollTo(x, y);}}}

下载地址


http://download.csdn.net/detail/u010785585/8062787


更多相关文章

  1. android 拖动图片移动效果
  2. 自定义VIEWGROUP的一个用法
  3. android圆形图片显示效果,带边框
  4. Android(安卓)模拟返回键功能
  5. android 拖动图片移动效果
  6. Android之setResult的用法
  7. android之OnGestureListener实现图片的左右滑动
  8. Android(安卓)studio DrawerLayout
  9. android实现播放器反射性动画效果

随机推荐

  1. tiny210的android编译过程
  2. Android 点击赞时弹出+1向上弹出动画
  3. Android ListView的使用
  4. Android 打开闪光灯(手电筒)
  5. [置顶] android 捕捉异常
  6. android save bitmap
  7. android driver for ubuntu 手机驱动
  8. Android 多层树完美实现
  9. Android(安卓)图文数据JSON解析,金山词霸
  10. Android TextView自带padding 10dp问题