一、去除自带边框点击效果:
1
二、去除右侧滚动条
1 package com.example.gridview; 2 3 import android.content.Context; 4 import android.util.AttributeSet; 5 6 public class MyGridView extends android.widget.GridView { 7 public MyGridView(Context context, AttributeSet attrs) { 8 super(context, attrs); 9 }10 11 public MyGridView(Context context) {12 super(context);13 }14 15 public MyGridView(Context context, AttributeSet attrs, int defStyle) {16 super(context, attrs, defStyle);17 }18 //重写了GridView的onMeasure方法,使其不会出现滚动条19 @Override20 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {21 int expandSpec = MeasureSpec.makeMeasureSpec(22 Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);23 super.onMeasure(widthMeasureSpec, expandSpec);24 }25 }
三、禁止上下滑动
1 package com.example.gridview; 2 3 import android.content.Context; 4 import android.util.AttributeSet; 5 6 public class MyGridView2 extends android.widget.GridView{ 7 8 public HotKeyGridView(Context context, AttributeSet attrs, int defStyle) { 9 super(context, attrs, defStyle); 10 } 11 12 public HotKeyGridView(Context context, AttributeSet attrs) { 13 super(context, attrs); 14 } 15 16 public HotKeyGridView(Context context) { 17 super(context); 18 } 19 20 21 public boolean dispatchTouchEvent(MotionEvent ev) { 22 if(ev.getAction() == MotionEvent.ACTION_MOVE){ 23 return true;//禁止Gridview进行滑动 24 } 25 return super.dispatchTouchEvent(ev); 26 } 27 }