锁定gridview的滚动 [英] Locking scroll of gridview
本文介绍了锁定gridview的滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的UI 1的GridView,但垂直滚动我已经设置所有滚动条属性为假,但它仍然滚动。任何想法,为什么会这样?请大家帮忙。
这是我的布局
<?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent机器人:layout_height =match_parent
机器人:背景=@绘制/ bg_im机器人:ID =@ + ID / rLayout机器人:isScrollContainer =假> < LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / lLayoutCalendar机器人:方向=垂直
机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT
机器人:layout_toRightOf =@ + ID / linearLayoutLeftTask机器人:比重=CENTER_HORIZONTAL
机器人:layout_marginLeft =10dp机器人:layout_marginRight =10dp
机器人:layout_marginTop =20dp机器人:背景=@绘制/ calendar_bgnew机器人:isScrollContainer =假> < LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=横向的android:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT机器人:layout_gravity =center_vertical
机器人:滚动条=无机器人:isScrollContainer =假
机器人:layout_marginTop =8DP> < ImageView的机器人:ID =@ + ID / prevMonth
机器人:layout_width =WRAP_CONTENT机器人:layout_marginLeft =10dp
机器人:layout_marginTop =5DP机器人:layout_height =WRAP_CONTENT
机器人:SRC =@绘制/ calendar_arrow_ previous>
< / ImageView的>
<按钮机器人:ID =@ + ID / currentMonth机器人:layout_weight =0.8
机器人:文字颜色=@机器人:彩色/黑白机器人:textAppearance =机器人:ATTR / textAppearanceMedium
机器人:背景=@机器人:彩色/透明的机器人:文字样式=大胆
机器人:TEXTSIZE =16SP的android:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
< /按钮>
< ImageView的机器人:ID =@ + ID / nextMonth
机器人:layout_marginRight =10dp机器人:layout_marginTop =5DP
机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT
机器人:SRC =@绘制/ calendar_arrow_next>
< / ImageView的>
< / LinearLayout中>
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=横向的android:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT机器人:paddingLeft =5DP
机器人:layout_marginTop =10dp的android:paddingRight =5DP> < TextView的机器人:字体=SANS机器人:layout_marginTop =12dp
机器人:paddingLeft =5DP机器人:文本=苏机器人:layout_height =WRAP_CONTENT
机器人:TEXTSTYLE =正常的机器人:文字颜色=#7e7f7e
机器人:layout_width =65px>
< / TextView的>
< TextView的机器人:字体=SANS机器人:layout_marginTop =12dp
机器人:文字=墨子机器人:layout_height =WRAP_CONTENT
机器人:TEXTSTYLE =正常的机器人:文字颜色=#7e7f7e
机器人:layout_width =65px>
< / TextView的>
< TextView的机器人:字体=SANS机器人:layout_marginTop =12dp
机器人:文字=屠机器人:layout_height =WRAP_CONTENT
机器人:TEXTSTYLE =正常的机器人:文字颜色=#7e7f7e
机器人:layout_width =63px>
< / TextView的>
< TextView的机器人:字体=SANS机器人:layout_marginTop =12dp
机器人:文字=我们机器人:layout_height =WRAP_CONTENT
机器人:TEXTSTYLE =正常的机器人:文字颜色=#7e7f7e
机器人:layout_width =63px>
< / TextView的>
< TextView的机器人:字体=SANS机器人:layout_marginTop =12dp
机器人:文字=TH机器人:layout_height =WRAP_CONTENT
机器人:TEXTSTYLE =正常的机器人:文字颜色=#7e7f7e
机器人:layout_width =63px>
< / TextView的>
< TextView的机器人:字体=SANS机器人:layout_marginTop =12dp
机器人:文字=FR机器人:layout_height =WRAP_CONTENT
机器人:TEXTSTYLE =正常的机器人:文字颜色=#7e7f7e
机器人:layout_width =63px>
< / TextView的>
< TextView的机器人:字体=SANS机器人:layout_marginTop =12dp
机器人:paddingLeft =5DP机器人:文本=SA机器人:layout_height =WRAP_CONTENT
机器人:TEXTSTYLE =正常的机器人:文字颜色=#7e7f7e
机器人:layout_width =63px>
< / TextView的>
< / LinearLayout中>
< GridView的机器人:为numColumns =7机器人:layout_marginTop =5DP的风格=溢出:锁
机器人:layout_marginBottom =10dp的android:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT机器人:ID =@ + ID /日历
机器人:horizontalSpacing = - 1px的机器人:verticalSpacing = - 1像素
机器人:layout_marginLeft =2DP机器人:isScrollContainer =假
机器人:smoothScrollbar =false的机器人:stackFromBottom =假
机器人:fastScrollEnabled =false的机器人:stretchMode =columnWidth中机器人:fadeScrollbars =假>
< / GridView的>
< / LinearLayout中>
< / RelativeLayout的>
解决方案
尝试添加或覆盖 setOnTouchListener
为GridView控件,然后onTouch方法,你可以用code这样做的GridView不滚动:
gridview.setOnTouchListener(新OnTouchListener(){ @覆盖
公共布尔onTouch(视图V,MotionEvent事件){
如果(event.getAction()== MotionEvent.ACTION_MOVE){
返回true;
}
返回false;
}});
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>
解决方案
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;
}
});
这篇关于锁定gridview的滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文