一、去除自带边框点击效果:
1 <com.example.gridview.MyGridView 2 android:id="@+id/grid_upload_pictures" 3 android:layout_width="0dp" 4 android:layout_weight="2" 5 android:paddingLeft="20dp" 6 android:listSelector="@android:color/transparent" 7 android:layout_height="wrap_content" 8 android:horizontalSpacing="10dp" 9 android:verticalSpacing="10dp" 10 android:numColumns="1" 11 android:stretchMode="columnWidth"/>
二、去除右侧滚动条
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 @Override 20 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 }