一、去除自带边框点击效果:

 <com.example.gridview.MyGridView
android:id="@+id/grid_upload_pictures"
android:layout_width="0dp"
android:layout_weight="2"
android:paddingLeft="20dp"
android:listSelector="@android:color/transparent"
android:layout_height="wrap_content"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:numColumns="1"
android:stretchMode="columnWidth"/>

二、去除右侧滚动条

 package com.example.gridview;

 import android.content.Context;
import android.util.AttributeSet; public class MyGridView extends android.widget.GridView {
public MyGridView(Context context, AttributeSet attrs) {
super(context, attrs);
} public MyGridView(Context context) {
super(context);
} public MyGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
//重写了GridView的onMeasure方法,使其不会出现滚动条
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}

三、禁止上下滑动

 package com.example.gridview;

 import android.content.Context;
import android.util.AttributeSet; public class MyGridView2 extends android.widget.GridView{ public HotKeyGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
} public HotKeyGridView(Context context, AttributeSet attrs) {
super(context, attrs);
} public HotKeyGridView(Context context) {
super(context);
} public boolean dispatchTouchEvent(MotionEvent ev) {
if(ev.getAction() == MotionEvent.ACTION_MOVE){
return true;//禁止Gridview进行滑动
}
return super.dispatchTouchEvent(ev);
}
}

感谢:

http://blog.csdn.net/super11235/article/details/55050141

http://blog.csdn.net/go_to_learn/article/details/17761735

05-11 22:42