Android雙列滑動表格(雙表頭不動)

來源:互聯網
上載者:User

標籤:android 雙列 滑動 表格 表頭

※效果


※用法
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雙列滑動表格(雙表頭不動)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.