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);
	}
}

不分发 滑动事件即可。

你可能感兴趣的:(android GridView 去掉自带点击边框效果和禁止上下滑动)