2012-06-20 10 views
13

मैं यहां नया उपयोगकर्ता हूं और एक एंड्रॉइड ऐप काम कर रहा हूं जो कस्टम स्क्रॉल व्यू (नीचे दिए गए लिंक के रूप में दिखाया गया है) का अनुरोध करता है। यह पहली छवि को छोड़कर ग्रिडव्यू जैसा ही है। मैंने ग्रिडव्यू के साथ एक बड़ी छविदृश्य जोड़ने का उपयोग करने की कोशिश की। लेकिन यह विफल रहता है। किसी के पास कोई सुझाव है?ग्रिडव्यू एंड्रॉइड के पहले आइटम के लिए बड़ी छवि

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

मैं छवि दृश्य के साथ दो ग्रिडव्यू आइटमों के बीच टेक्स्ट व्यू कैसे जोड़ सकता हूं? – ClarkXP

संबंधित मुद्दे