GridView控件滚动奇怪的问题 [英] GridView scrolling weird issue
问题描述
让我解释一下我的问题。
我使用的是自定义适配器的GridView,一切工作正常。正如标题所说的问题是当我滚动快。
滚动缓慢作品完美,但是当我滚动速度快,到达终点,我有一个像回扣给电网的中间,但是当我从后面顶端快速滚动这个问题不apear。
我使用的是4.2版本的SDK编码2.3.3。
我测试在2.3.3真正的手机和一个4.2模拟器,相同的结果。
谢谢您即将成为答案! (对不起,我可怜的书面英语)
下面你是我的适配器的code。
进口的java.util.ArrayList;进口android.content.Context;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.view.ViewGroup;
进口android.widget.BaseAdapter;
进口android.widget.ImageView;
进口android.widget.TextView;@燮pressWarnings(未使用)
公共类RadioAdapter延伸BaseAdapter {
私人上下文的背景下;
私人最终的ArrayList<无线>收音机;
私人LayoutInflater吹气; 公共RadioAdapter(上下文的背景下,ArrayList的<无线>收音机){
this.context =背景;
this.radios =收音机; 吹气=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
} @覆盖
公众诠释的getCount(){
返回radios.size();
} @覆盖
公共广播电台的getItem(INT位置){
// TODO自动生成方法存根
返回null;
} @覆盖
众长getItemId(INT位置){
// TODO自动生成方法存根
返回0;
} @覆盖
公共查看getView(INT位置,查看convertView,父母的ViewGroup){ ViewHolder持有人; Radio收音机功能= radios.get(位置); 如果(convertView == NULL){ convertView = inflater.inflate(R.layout.item,NULL); 持有人=新ViewHolder(); holder.textView =(TextView中)convertView.findViewById(R.id.grid_item_label);
holder.imageView =(ImageView的)convertView.findViewById(R.id.grid_item_cover); convertView.setTag(保持器);
}其他{
支架=(ViewHolder)convertView.getTag();
} holder.textView.setText(radio.getName()); holder.imageView.setImageResource(radio.getThumbnail()); 返回convertView;
} 公共静态类ViewHolder {
TextView中的TextView;
ImageView的ImageView的;
}
}
EDIT3:
一些研究之后,我发现这一点: https://github.com/Prototik/ HoloEverywhere /问题/ 282
您采用了android:overScrollMode =从来没有?有一个错误
的http:// code姜饼滚动实施。 google.com/p/android/issues/detail?id=15860
块引用>所以,我的问题是正常的姜饼,该死的。
我用手机4.0.3测试,它工作正常。问题解决了。
EDIT2:
我发现,这个问题带有
的android:overScrollMode =从不
编辑:
下面你是我的布局:
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
工具:上下文=MainActivity。> < ImageView的
机器人:ID =@ + ID / imageView1
机器人:scaleType =fitStart
机器人:adjustViewBounds =真
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentTop =真
机器人:SRC =@绘制/ top_bar/> <的TextView
机器人:ID =@ + ID / textView1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerHorizontal =真
机器人:文字=@字符串/ APP_NAME
机器人:textAppearance =机器人:ATTR / textAppearanceLarge
机器人:文字颜色=@色/白
机器人:layout_alignLeft =@ + ID / imageView1
机器人:layout_alignTop =@ + ID / imageView1
机器人:layout_alignRight =@ + ID / imageView1
机器人:layout_alignBottom =@ + ID / imageView1
机器人:比重=中心/> < censored.RadioView
机器人:layout_below =@ ID / imageView1
机器人:ID =@ + ID / gridView1
机器人:为numColumns =auto_fit
机器人:columnWidth时=100dp
机器人:stretchMode =spacingWidthUniform
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:listSelector =@绘制/ grid_selector
机器人:drawSelectorOnTop =假
机器人:overScrollMode =从不
机器人:fadingEdge =无
机器人:滚动条=无>
< /censored.RadioView>
< / RelativeLayout的>和我RadioView的code
进口android.content.Context;
进口android.graphics.Bitmap;
进口android.graphics.BitmapFactory;
进口android.graphics.Canvas;
进口android.util.AttributeSet;
进口android.widget.GridView;公共类RadioView扩展GridView控件{
私人位图的背景; 公共RadioView(上下文的背景下){
超级(上下文);
在里面();
} 公共RadioView(上下文的背景下,ATTRS的AttributeSet){
超(背景下,ATTRS);
在里面();
} 公共RadioView(上下文的背景下,ATTRS的AttributeSet,诠释defStyle){
超(背景下,ATTRS,defStyle);
在里面();
} 保护无效的init(){
背景= BitmapFactory.de codeResource(getResources(),R.drawable.shelfcell_bgr);
} @覆盖
保护无效dispatchDraw(帆布油画){
INT顶= getChildCount()> 0? getChildAt(0).getTop():0;
对于(INT Y =顶部; Y<的getHeight(); Y + = background.getHeight()){
为(中间体X = 0; X&下;的getWidth(); X + = background.getWidth()){
canvas.drawBitmap(背景,X,Y,空);
}
}
super.dispatchDraw(画布);
}
}
解决方案在一些更多的研究,我发现这一点:
https://github.com/Prototik/HoloEverywhere/issues/282
您采用了android:overScrollMode =从来没有?有一个错误
姜饼滚动实施:
HTTP://$c$c.google.com/p /安卓/问题/细节?ID = 15860
块引用>所以,我的问题是正常的姜饼,该死的。
我用手机4.0.3测试,它工作正常。问题解决了。
let me explain my problem.
I'm using a GridView with a custom adapter, and everything works fine. As the title says the problem comes when I scroll fast.
Scrolling slow works perfectly, but when I scroll fast and reach end I've got like a "kickback" to the middle of the grid, but this problem doesn't apear when I scroll fast from the back to the top.
I'm coding for 2.3.3 using 4.2 sdk version. I'm testing on a 2.3.3 real phone and on a 4.2 emulator, same results.
Thanks for your futur answer ! (Sorry for my poor written English)
Here you are the code of my adapter.
import java.util.ArrayList; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; @SuppressWarnings("unused") public class RadioAdapter extends BaseAdapter { private Context context; private final ArrayList<Radio> radios; private LayoutInflater inflater; public RadioAdapter(Context context, ArrayList<Radio> radios) { this.context = context; this.radios = radios; inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public int getCount() { return radios.size(); } @Override public Radio getItem(int position) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; Radio radio = radios.get(position); if (convertView == null) { convertView = inflater.inflate(R.layout.item, null); holder = new ViewHolder(); holder.textView = (TextView) convertView.findViewById(R.id.grid_item_label); holder.imageView = (ImageView) convertView.findViewById(R.id.grid_item_cover); convertView.setTag(holder); } else { holder = (ViewHolder)convertView.getTag(); } holder.textView.setText(radio.getName()); holder.imageView.setImageResource(radio.getThumbnail()); return convertView; } public static class ViewHolder { TextView textView; ImageView imageView; } }
EDIT3:
After some more research I've found this : https://github.com/Prototik/HoloEverywhere/issues/282
Are you using android:overScrollMode="never"? There is a bug in scroller implementation in Gingerbread: http://code.google.com/p/android/issues/detail?id=15860
So the problem I have is normal on Gingerbread, damn.
I've tested with a 4.0.3 phone and it works normally. Problem solved.
EDIT2:
I've detected that the problem comes with
android:overScrollMode="never"
EDIT:
Here you are my layout :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" tools:context=".MainActivity" > <ImageView android:id="@+id/imageView1" android:scaleType="fitStart" android:adjustViewBounds="true" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:src="@drawable/top_bar" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="@string/app_name" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@color/White" android:layout_alignLeft="@+id/imageView1" android:layout_alignTop="@+id/imageView1" android:layout_alignRight="@+id/imageView1" android:layout_alignBottom="@+id/imageView1" android:gravity="center" /> <censored.RadioView android:layout_below="@id/imageView1" android:id="@+id/gridView1" android:numColumns="auto_fit" android:columnWidth="100dp" android:stretchMode="spacingWidthUniform" android:layout_width="fill_parent" android:layout_height="fill_parent" android:listSelector="@drawable/grid_selector" android:drawSelectorOnTop="false" android:overScrollMode="never" android:fadingEdge="none" android:scrollbars="none"> </censored.RadioView> </RelativeLayout>
And the code of my RadioView
import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.util.AttributeSet; import android.widget.GridView; public class RadioView extends GridView{ private Bitmap background; public RadioView(Context context) { super(context); init(); } public RadioView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public RadioView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } protected void init() { background = BitmapFactory.decodeResource(getResources(), R.drawable.shelfcell_bgr); } @Override protected void dispatchDraw(Canvas canvas) { int top = getChildCount() > 0 ? getChildAt(0).getTop() : 0; for (int y = top; y < getHeight(); y += background.getHeight()){ for (int x = 0; x < getWidth(); x += background.getWidth()){ canvas.drawBitmap(background, x, y, null); } } super.dispatchDraw(canvas); } }
解决方案After some more research I've found this : https://github.com/Prototik/HoloEverywhere/issues/282
Are you using android:overScrollMode="never"? There is a bug in scroller implementation in Gingerbread: http://code.google.com/p/android/issues/detail?id=15860
So the problem I have is normal on Gingerbread, damn.
I've tested with a 4.0.3 phone and it works normally. Problem solved.
这篇关于GridView控件滚动奇怪的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!