Android双列滑动表格(双表头不动)
16lz
2022-03-18
※效果
※用法
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
更多相关文章
- android 拖动图片移动效果
- 自定义VIEWGROUP的一个用法
- android圆形图片显示效果,带边框
- Android(安卓)模拟返回键功能
- android 拖动图片移动效果
- Android之setResult的用法
- android之OnGestureListener实现图片的左右滑动
- Android(安卓)studio DrawerLayout
- android实现播放器反射性动画效果