2012-12-09 77 views
0

我的圖庫中的每個項目都是自定義視圖。其中一個孩子的觀點是一個gridView。當我滾動畫廊一切正常,但它不會通過觸摸gridView滾動。它很難解釋,我希望有人會理解我! 觸摸並滾動自定義視圖的任何部分假設觸發滾動?或者也許只有imageView會觸發滾動?在圖庫中滾動子視圖

public View getView(int position, View convertView, ViewGroup parent) { 

    final SubProduct subProduct=subProducts.get(position); 
    int quantity=subProduct.getQuantity(); 
    int size=subProduct.getSizes().get(0).getWidth(); 
    String productName=subProduct.getProductName(); 
    int productPrice=subProduct.getSizes().get(0).getPrice(); 
    int columnWidth = 0; 

    View view=convertView; 

    if (view==null){ 

     holder=new SubProductHolder(); 

     //The main container 
     holder.myLinearLayout= new LinearLayout(this.myContext); 
     holder.myLinearLayout.setOrientation(1);//vertical 

     //The custome button 
     LayoutInflater inflater = (LayoutInflater) 
       myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View v=(View)inflater.inflate(R.layout.custom_sub_product_layout, null); 
     LinearLayout btnLayout = (LinearLayout)v.findViewById(R.id.customSunProductButtonLayout); 
     LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(PRODUCT_BOTTUN_WIDTH,PRODUCT_BOTTUN_HEIGHT); 
     btnLayout.setLayoutParams(llp); 
     tvSubProductDescription=(TextView)v.findViewById(R.id.tvSubProductDescription); 
     tvSubProductPrice=(TextView) v.findViewById(R.id.tvSubProductPrice); 

     holder.btnProduct=btnLayout; 
     holder.btnProduct.setGravity(Gravity.CENTER); 
     holder.TvLinearLayout= new LinearLayout(this.myContext); 
     holder.TvLinearLayout.addView(holder.btnProduct); 

     //frame     
     holder.image = new ImageView(this.myContext); 
      holder.image.setBackgroundColor(Color.WHITE); 
     LinearLayout.LayoutParams llp2 = new LinearLayout.LayoutParams(FRAME_WIDTH,FRAME_WIDTH); 
     holder.image.setLayoutParams(llp2); 

     //grid 
     holder.grid=new GridView(myContext); 
     //the number of rows is the round number of quantity sqaure 
     int numberOfColomns=(int) Math.floor((int) Math.sqrt(quantity)); 
     holder.grid.setNumColumns(numberOfColomns); 
     holder.grid.setLayoutParams(new RelativeLayout.LayoutParams(PRODUCT_PICTURE_WIDTH,PRODUCT_PICTURE_WIDTH)); 

    }else{ 
     holder=(SubProductHolder)view.getTag(); 
    } 

    //set text in description tv 
    tvSubProductDescription.setText(quantity+" "+productName+" "+size+"X"+size); 
    tvSubProductPrice.setText("$"+productPrice); 

    //set the grid 
    holder.grid.setAdapter(new emptySquaresAdapter(quantity,myContext,columnWidth,columnHeight)); 
    holder.relativeGridLayout=new RelativeLayout(myContext); 
    holder.relativeGridLayout.addView(holder.image); 

    holder.relativeGridLayout.addView(holder.grid); 

    //set button and picture to layout 
    holder.myLinearLayout.addView(holder.relativeGridLayout); 
    holder.myLinearLayout.addView(holder.TvLinearLayout); 

    return holder.myLinearLayout; 
} 


static class SubProductHolder 
{ 
    ImageView image; 
    GridView grid; 
    RelativeLayout relativeGridLayout; 

    LinearLayout btnProduct; 
    LinearLayout TvLinearLayout; 

    LinearLayout myLinearLayout; 
} 

回答

1

你必須使用圖庫視圖TouchListeners因爲在點擊其子視圖圖庫視圖

+0

謝謝。儘管我一直在尋找範例,但我在實施聽衆方面遇到了麻煩。它是onFling方法,我需要重寫?@lochana – user1787773

+0

是的,它是onfling方法,你是對的 –

1

你必須使用TouchListeners不會觸發滾動。另外,你最好使用ViewPager並使用片段。據我所知,Gallery已過時。