2012-06-20 40 views
13

我是新用戶在這裏和工作的android應用程序請求自定義滾動視圖(如下面的鏈接所示)。除了第一個圖像,它和gridview非常相似。我試圖使用與gridview一起添加一個大的圖像查看。但它失敗了。任何人有任何建議?gridview的第一項更大的圖像android

enter image description here

回答

9

我奶源得到後續的使用下面的代碼圖像: enter image description here

我移動代碼這個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> 
+1

避免張貼滿工作的應用,堅持片段,它更有效地提出一個觀點。 – JoxTraex

+0

我已經創建了一個博客http://sudarnimalan.blogspot.sg/2012/06/android-bigger-image-for-first-item-of.html來解釋這一點。 1.需要檢查getView方法,2.檢查開關(arg0),如果情況0,情況1,情況5和情況6設置位圖的左上角,右上角,左下角,右下角部分。 –

+0

如何在兩個gridview項目之間添加TextView,就像使用ImageView創建的一樣? – ClarkXP

相關問題