Reputation: 1331
I have one gridview in my UI but it scrolls vertically I have set all the scrollbar properties as false but its still scrolling. Any idea why this is so? please help.
This is my layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@drawable/bg_im" android:id="@+id/rLayout" android:isScrollContainer="false">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lLayoutCalendar" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="@+id/linearLayoutLeftTask" android:gravity="center_horizontal"
android:layout_marginLeft="10dp" android:layout_marginRight="10dp"
android:layout_marginTop="20dp" android:background="@drawable/calendar_bgnew" android:isScrollContainer="false">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_gravity="center_vertical"
android:scrollbars="none" android:isScrollContainer="false"
android:layout_marginTop="8dp">
<ImageView android:id="@+id/prevMonth"
android:layout_width="wrap_content" android:layout_marginLeft="10dp"
android:layout_marginTop="5dp" android:layout_height="wrap_content"
android:src="@drawable/calendar_arrow_previous">
</ImageView>
<Button android:id="@+id/currentMonth" android:layout_weight="0.8"
android:textColor="@android:color/black" android:textAppearance="?android:attr/textAppearanceMedium"
android:background="@android:color/transparent" android:textStyle="bold"
android:textSize="16sp" android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
<ImageView android:id="@+id/nextMonth"
android:layout_marginRight="10dp" android:layout_marginTop="5dp"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/calendar_arrow_next">
</ImageView>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:paddingLeft="5dp"
android:layout_marginTop="10dp" android:paddingRight="5dp">
<TextView android:typeface="sans" android:layout_marginTop="12dp"
android:paddingLeft="5dp" android:text="Su" android:layout_height="wrap_content"
android:textStyle="normal" android:textColor="#7e7f7e"
android:layout_width="65px">
</TextView>
<TextView android:typeface="sans" android:layout_marginTop="12dp"
android:text="Mo" android:layout_height="wrap_content"
android:textStyle="normal" android:textColor="#7e7f7e"
android:layout_width="65px">
</TextView>
<TextView android:typeface="sans" android:layout_marginTop="12dp"
android:text="Tu" android:layout_height="wrap_content"
android:textStyle="normal" android:textColor="#7e7f7e"
android:layout_width="63px">
</TextView>
<TextView android:typeface="sans" android:layout_marginTop="12dp"
android:text="We" android:layout_height="wrap_content"
android:textStyle="normal" android:textColor="#7e7f7e"
android:layout_width="63px">
</TextView>
<TextView android:typeface="sans" android:layout_marginTop="12dp"
android:text="Th" android:layout_height="wrap_content"
android:textStyle="normal" android:textColor="#7e7f7e"
android:layout_width="63px">
</TextView>
<TextView android:typeface="sans" android:layout_marginTop="12dp"
android:text="Fr" android:layout_height="wrap_content"
android:textStyle="normal" android:textColor="#7e7f7e"
android:layout_width="63px">
</TextView>
<TextView android:typeface="sans" android:layout_marginTop="12dp"
android:paddingLeft="5dp" android:text="Sa" android:layout_height="wrap_content"
android:textStyle="normal" android:textColor="#7e7f7e"
android:layout_width="63px">
</TextView>
</LinearLayout>
<GridView android:numColumns="7" android:layout_marginTop="5dp" style="overflow:lock"
android:layout_marginBottom="10dp" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/calendar"
android:horizontalSpacing="-1px" android:verticalSpacing="-1px"
android:layout_marginLeft="2dp" android:isScrollContainer="false"
android:smoothScrollbar="false" android:stackFromBottom="false"
android:fastScrollEnabled="false" android:stretchMode="columnWidth" android:fadeScrollbars="false">
</GridView>
</LinearLayout>
</RelativeLayout>
Upvotes: 3
Views: 6739
Reputation: 180
Use this custom gridview. It automatically sets the height and does not scroll:
public class MyGridView extends GridView {
public MyGridView(Context context) {
super(context);
}
public MyGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightSpec;
if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) {
// The great Android "hackatlon", the love, the magic.
// The two leftmost bits in the height measure spec have
// a special meaning, hence we can't use them to describe height.
heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
} else {
heightSpec = heightMeasureSpec;
}
super.onMeasure(widthMeasureSpec, heightSpec);
}
}
Upvotes: 3
Reputation: 1
public class myGridView extends GridView {
public myGridView(Context context) {
super(context);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
return super.onTouchEvent(event);
case MotionEvent.ACTION_MOVE:
//Do nothing here!!!
break;
case MotionEvent.ACTION_UP:
return super.onTouchEvent(event);
}
//false return
return false;
}
}
Upvotes: 0
Reputation: 35946
Try to add or override setOnTouchListener
for GridView, then in onTouch method you can use code like this to make gridview not scrolling :
gridview.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_MOVE){
return true;
}
return false;
}
});
Upvotes: 6
Reputation: 1006799
GridView
is designed to scroll vertically, and I am not aware that you can stop it from scrolling. If you do not want scrolling, do not use a GridView
.
Upvotes: 1