1. 程式人生 > >android GridView 去掉自帶點選邊框效果和禁止上下滑動

android GridView 去掉自帶點選邊框效果和禁止上下滑動

1.去掉自帶點選邊框效果:

    <com.yw.store.ui.HotKeyGridView
        android:id="@+id/search_home_gridview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:horizontalSpacing="10dp"
        android:listSelector="@android:color/transparent"  
        android:numColumns="3"
        android:verticalSpacing="10dp" >
    </com.yw.store.ui.HotKeyGridView>

設定屬性:android:listSelector="@android:color/transparent"  即可.

2.禁止上下滑動

public class HotKeyGridView extends GridView {

	public HotKeyGridView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}

	public HotKeyGridView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	public HotKeyGridView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}


	public boolean dispatchTouchEvent(MotionEvent ev) {
		// TODO Auto-generated method stub
		if(ev.getAction() == MotionEvent.ACTION_MOVE){
			return true;//禁止Gridview進行滑動
		}
		return super.dispatchTouchEvent(ev);
	}
}

不分發 滑動事件即可。