横向滑动的 ListView
来源:互联网 发布:gcc可用windows界面库 编辑:程序博客网 时间:2024/05/09 23:52
public class HVListView extends ListView {private GestureDetector mGesture;public LinearLayout mListHead;private int mOffset = 0;private int screenWidth;public HVListView(Context context) {super(context);mGesture = new GestureDetector(context, mOnGesture);}public HVListView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);mGesture = new GestureDetector(context, mOnGesture);}public HVListView(Context context, AttributeSet attrs) {super(context, attrs);mGesture = new GestureDetector(context, mOnGesture);}@Overridepublic boolean dispatchTouchEvent(MotionEvent ev) {super.dispatchTouchEvent(ev);return mGesture.onTouchEvent(ev);}private OnGestureListener mOnGesture = new GestureDetector.SimpleOnGestureListener() {@Overridepublic boolean onDown(MotionEvent e) {return true;}@Overridepublic boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {return false;}@Overridepublic boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {synchronized (HVListView.this) {if (Math.abs(distanceX) > Math.abs(distanceY)) {int moveX = (int) distanceX;int curX = mListHead.getScrollX();//int scrollWidth = getWidth();int scrollWidth = (int)( 890 * getContext().getResources().getDisplayMetrics().density);int dx = moveX;if (curX + moveX < 0)dx = 0;if (curX + moveX + getScreenWidth() > scrollWidth)dx = scrollWidth - getScreenWidth() - curX;mOffset += dx;for (int i = 0, j = getChildCount(); i < j; i++) {View child = ((ViewGroup) getChildAt(i)).getChildAt(1);if (child.getScrollX() != mOffset)child.scrollTo(mOffset, 0);}mListHead.scrollBy(dx, 0);}}requestLayout();return true;}};public int getScreenWidth() {if (screenWidth == 0) {screenWidth = getContext().getResources().getDisplayMetrics().widthPixels;if (getChildAt(0) != null) {screenWidth -= ((ViewGroup) getChildAt(0)).getChildAt(0).getMeasuredWidth();} else if (mListHead != null) {screenWidth -= mListHead.getChildAt(0).getMeasuredWidth();}}return screenWidth;}public int getHeadScrollX() {return mListHead.getScrollX();}public LinearLayout getListHead() {return mListHead;}public void setListHead(LinearLayout listHead) {this.mListHead = listHead;}}
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"android:layout_height="match_parent" ><LinearLayout xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#F6F6F6" android:orientation="vertical" android:paddingBottom="2dip" tools:context=".MainActivity" > <!-- 和分公司运营数据界面查不多 --> <include android:id="@+id/title_include_layout" android:layout_width="fill_parent" android:layout_height="wrap_content" layout="@layout/toptitle_include" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/city_hall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="20dip" android:text="所有城区的分公司" android:textColor="@color/black" android:textSize="20sp" /> <TextView android:id="@+id/currentTime" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginBottom="20dip" android:layout_marginTop="20dip" android:text="显示默认服务器时间" android:textColor="@color/black" android:textSize="14sp" /> <View android:id="@+id/view_one" android:layout_width="fill_parent" android:layout_height="1dip" android:layout_marginLeft="5dip" android:layout_marginRight="5dip" android:background="#B4B6B7" /> <LinearLayout android:id="@+id/headLayout" android:layout_width="1050dip" android:layout_height="35dip" android:layout_marginLeft="5dip" android:layout_marginRight="5dip" android:orientation="horizontal" > <!-- 这里第一列的宽度进行固定 --> <View android:layout_width="1dip" android:layout_height="fill_parent" android:background="#B4B6B7" /> <TextView style="@style/TextStyleBack" android:layout_width="158dp" android:layout_height="fill_parent" android:text="营业厅名称" /> <View android:layout_width="1dip" android:layout_height="fill_parent" android:background="#B4B6B7" /> <LinearLayout android:id="@+id/headView" android:layout_width="880dip" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView style="@style/TextStyleBack" android:layout_width="99dp" android:layout_height="fill_parent" android:text="取号人数" /> <View android:layout_width="1dip" android:layout_height="fill_parent" android:background="#B4B6B7" /> <TextView style="@style/TextStyleBack" android:layout_width="99dp" android:layout_height="fill_parent" android:text="服务人数" /> <View android:layout_width="1dip" android:layout_height="fill_parent" android:background="#B4B6B7" /> <TextView style="@style/TextStyleBack" android:layout_width="99dp" android:layout_height="fill_parent" android:text="弃号人数" /> <View android:layout_width="1dip" android:layout_height="fill_parent" android:background="#B4B6B7" /> <TextView style="@style/TextStyleBack" android:layout_width="99dp" android:layout_height="fill_parent" android:text="等待人数" /> <View android:layout_width="1dip" android:layout_height="fill_parent" android:background="#B4B6B7" /> <TextView style="@style/TextStyleBack" android:layout_width="119dp" android:layout_height="fill_parent" android:text="平均服务时间" /> <View android:layout_width="1dip" android:layout_height="fill_parent" android:background="#B4B6B7" /> <TextView style="@style/TextStyleBack" android:layout_width="119dp" android:layout_height="fill_parent" android:text="平均等待时间" /> <View android:layout_width="1dip" android:layout_height="fill_parent" android:background="#B4B6B7" /> <TextView style="@style/TextStyleBack" android:layout_width="119dp" android:layout_height="fill_parent" android:text="台席开放率" /> <View android:layout_width="1dip" android:layout_height="fill_parent" android:background="#B4B6B7" /> <TextView style="@style/TextStyleBack" android:layout_width="119dp" android:layout_height="fill_parent" android:text="台席开放数" /> <View android:layout_width="1dip" android:layout_height="fill_parent" android:background="#B4B6B7" /> </LinearLayout> </LinearLayout> <View android:id="@+id/view_two" android:layout_width="fill_parent" android:layout_height="1dip" android:layout_marginLeft="5dip" android:layout_marginRight="5dip" android:background="#B4B6B7" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <com.ibm.moa.servicemanager.view.HVListView android:id="@+id/hallListView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dip" android:layout_marginRight="5dip" android:layout_weight="1" android:cacheColorHint="@color/transparent" android:divider="#B4B6B7" android:dividerHeight="1dip" android:fadingEdge="none" /> <!-- android:scrollbars="none" --> <!-- <View android:id="@+id/bottom_line" android:background="#B4B6B7" android:layout_width="fill_parent" android:layout_marginLeft="5dip" android:layout_marginRight="5dip" android:layout_height="1dip" android:visibility="visible" /> --> <include android:id="@+id/loadMore" android:layout_width="fill_parent" android:layout_height="wrap_content" layout="@layout/loadmore_footer_view" android:visibility="gone" /> </LinearLayout> </LinearLayout><include android:layout_width="fill_parent" android:layout_height="wrap_content" layout="@layout/tishi" /></FrameLayout>
View child = ((ViewGroup) convertView).getChildAt(1);
int headScrollX = hallListView.getHeadScrollX();
if (child.getScrollX() != headScrollX) {
child.scrollTo(hallListView.getHeadScrollX(), 0);
}
0 0
- 横向滑动的 ListView
- 横向滑动的listview
- 横向滑动的ListView
- 横向滑动的listview
- Android横向滑动的listview
- 可以横向滑动竖向滑动的listview
- android自定义控件--横向滑动的ListView
- 横向滑动可以删除的listView
- Android开发--横向滑动的listview
- Android--Listview横向滑动
- ListView横向滑动
- listView横向滑动
- ListView横向滑动
- Android Listview横向滑动
- ListView横向滑动
- 解决ScrollView嵌套RecyclerView(横向)或ListView(横向)时,横向滑动不顺畅的问题。
- 解决Android Listview横向滑动
- 解决Android Listview横向滑动
- HDU 1253(BFS)
- Spring Security教程(4)---- 数据库表结构的创建
- 通过JClassLib修改Class文件
- 点滴:Android 调试工具TraceView
- gdb调试时设置断点和观察点及其区别
- 横向滑动的 ListView
- 垃圾回收器的基本原理是什么?垃圾回收器可以马上回收内存吗?有什么办法主动通知虚拟机进行垃圾回收?
- 网页图表 开源工具Chart.js中关于Y轴数据从浮点数修改至整数展示的方法
- mp3gain 批量修改音量
- Android开发环境搭建全程演示(jdk+eclipse+android sdk)
- 阿里曾经收购过公司名单
- WPF-控件SAP焦点
- Spring3 MVC+Mybatis(个人记录仅供参考)
- 《那些事之Log4j》什么是log4j?【专题一】