14

I am new user here and working android app that requests a custom scroll view (shown as below link). It is very similar a gridview except the first image. I tried to use add a large imageview along with gridview. But it fails. Anyone has any suggestion?

enter image description here

ariefbayu
  • 21,849
  • 12
  • 71
  • 92
user1467903
  • 153
  • 2
  • 5

1 Answers1

9

I mange to get following image using the below code: enter image description here

I am moving the code to this blog:

// please check this part.
            @Override
            public View getView(int arg0, View arg1, ViewGroup arg2) {
                ImageView imageView;
                if(arg1==null){
                    imageView = new ImageView(DemoGridViewActivity.this){
                        @Override
                        protected void onMeasure(int widthMeasureSpec,
                                int heightMeasureSpec) {
                            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                            setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
                        }
                    };
                }else{
                    imageView = (ImageView) arg1;
                }

                imageView.setLayoutParams(new GridView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
                imageView.setBackgroundColor(Color.BLUE);
                imageView.setScaleType(ScaleType.FIT_XY);
                Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
//according to the position return proper imageview with bitmap
//for case 0 - top-left part
//for case 1 - top-right
//for case 5 - bottom-left
//for case 6 - bottom-right


                switch(arg0){
                case 0:
                    imageView.setImageBitmap(Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth()/2, bitmap.getHeight()/2));
                    imageView.setBackgroundColor(Color.RED);
                    return imageView;
                case 1:
                    imageView.setImageBitmap(Bitmap.createBitmap(bitmap, bitmap.getWidth()/2, 0, bitmap.getWidth()/2, bitmap.getHeight()/2));
                    imageView.setBackgroundColor(Color.GREEN);
                    return imageView;
                case 5:
                    imageView.setImageBitmap(Bitmap.createBitmap(bitmap, 0, bitmap.getHeight()/2, bitmap.getWidth()/2, bitmap.getHeight()/2));
                    imageView.setBackgroundColor(Color.YELLOW);
                    return imageView;
                case 6:
                    imageView.setImageBitmap(Bitmap.createBitmap(bitmap, bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getWidth()/2, bitmap.getHeight()/2));
                    imageView.setBackgroundColor(Color.MAGENTA);
                    return imageView;
                default:
                    imageView.setImageResource(R.drawable.ic_launcher);
                    return imageView;
                }
            }

        }
    }


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

        <GridView
            android:id="@+id/gridView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:numColumns="5" >
        </GridView>

</LinearLayout>
Sudar Nimalan
  • 3,962
  • 2
  • 20
  • 28
  • 1
    Avoid posting full working applications, stick to fragments, its more effective at making a point. – JoxTraex Jun 20 '12 at 04:46
  • I have created a blog http://sudarnimalan.blogspot.sg/2012/06/android-bigger-image-for-first-item-of.html to explain this. 1. need to check the getView method, 2. check switch(arg0) where in case 0,case 1, case 5 and case 6 set the top-left, top-right, bottom-left, bottom-right part of the bitmap. – Sudar Nimalan Jun 20 '12 at 12:51
  • How can I add a TextView between two gridview items like you has made with the ImageView? – ClarkXP Nov 16 '12 at 13:39