GridView scrolling problem on Android

后端 未结 5 1641
走了就别回头了
走了就别回头了 2021-02-02 03:06

this must be somethng very simple I\'m overlooking, but I have the following problem (the post is rather lengthy, but I want to provide as much info as possible :) ).

I

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-02 03:29

    guys to avoid this problem always return newly created object in getView()

    public View getView(int position, View convertView, ViewGroup parent) {
                    ImageView       imageView;
                    TextView        textView;
                    LinearLayout    linearlayout  = new LinearLayout(mContext);
                    //if (convertView == null) {
                        imageView       = new ImageView(mContext);
                        textView        = new TextView(mContext);
    
                        //imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
                        imageView.setAdjustViewBounds(false);
                        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                        imageView.setPadding(4, 8, 8, 8);                   
                        imageView.setBackgroundResource(mThumbIds[position]);
    
                        textView.setText(mThumbText[position]);                
                        textView.setGravity(0x01);
                        textView.setMaxLines(2);
    
                        //textView.setPadding(20, 0, 0, 0);
                        linearlayout.addView(imageView,0);
                        linearlayout.addView(textView,1);
                        linearlayout.setPadding(4, 4, 4, 4);
                        linearlayout.setOrientation(LinearLayout.VERTICAL);
                        linearlayout.setGravity(0x01);
    
                   // } else {
                        //linearlayout = (LinearLayout) convertView;
                    //}
    
                    return linearlayout;
                }
    

提交回复
热议问题