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;
}
4

2 回答 2

1

您必须为galleryView 使用TouchListeners,因为单击其子视图不会触发galleryView 的滚动

于 2012-12-09T13:01:58.307 回答
1

你必须使用 TouchListeners。此外,您最好使用 ViewPager 并使用片段。据我所知,Gallery 已被弃用。

于 2012-12-09T14:45:49.633 回答