/** 图片循环 */ private void initViewPager() { ViewGroup.LayoutParams mViewPagerlayoutParams = mViewPager.getLayoutParams(); if (mViewPagerlayoutParams != null) { mViewPagerlayoutParams.width = Misc.getScreenDisplay(this)[0]; mViewPagerlayoutParams.height = (int) (mViewPagerlayoutParams.width); mViewPager.setLayoutParams(mViewPagerlayoutParams); } mViewPager.setAdapter(new ProductDetailPicAdapter2(this, product.getImgList())); mViewPager.setOnPageChangeListener(this); // 设置布局参数 LinearLayout.LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); int marginParam = Misc.dip2px(this, 10) / 2; llytPagerPoiner.removeAllViewsInLayout(); for (int i = 0; i < product.getImgList().size(); i++) { // 设置按钮属性 View item = new ImageView(this); item.setBackgroundResource(R.drawable.recommend_gallery); item.setTag(String.valueOf(i)); // item.setOnClickListener(parentActivity); params.setMargins(marginParam, 0, marginParam, 0); params.weight = 1; llytPagerPoiner.addView(item, params); } llytPagerPoiner.getChildAt(0).setBackgroundResource(R.drawable.recommend_gallery_select); }
@Override public void onClick(View view) { switch (view.getId()) { case R.id.layout_trans_btn_back: finish(); break; case R.id.layout_trans_btn_cart: Intent intent2 = new Intent(this, CarsActivity.class); intent2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // intent2.putExtra(MainActivity.SWITCH_INDEX, 2); startActivity(intent2); break; case R.id.product_details_customer_service: break; case R.id.product_details_favourite: break; case R.id.product_details_addcart: showSkuPopupWindow(0); ActivityUtils.startScaleAnimotion(mScrollView, 0.85f, 0.85f); break; case R.id.product_details_buy_now: showSkuPopupWindow(1); ActivityUtils.startScaleAnimotion(mScrollView, 0.85f, 0.85f); break; case R.id.layout_product_comment_more: Intent intent4 = new Intent(this, CommentListActivity.class); intent4.putExtra("commentList", (Serializable) product.getCommentList()); intent4.putExtra("point", product.getCommentPoint()); intent4.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(intent4); break; default: break; } }
/** 填充数据 */ private void initData() { // Sku2 defaultSku = product.getSkuList().get(0); txtName.setText(product.getName()); txtDesc.setText(product.getDesc()); txtPrice.setText(product.getPrice()); txtPriceMarket.setText("市场价:" + product.getPrice()); txtSalesAmount.setText(product.getBuyerCount() + "人购买"); initViewPager(); // 图片循环 initServiceList(); // 服务列表 initPromotionList(); // 促销列表 initCommentList(); // 评论列表 mWebView.loadUrl("http://www.baidu.com"); ViewTreeObserver vto2 = txtPriceMarket.getViewTreeObserver(); vto2.addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { txtPriceMarket.getViewTreeObserver().removeGlobalOnLayoutListener(this); View view = findViewById(R.id.product_details_price_market_line); view.setVisibility(View.VISIBLE); ViewGroup.LayoutParams params = view.getLayoutParams(); params.width = txtPriceMarket.getWidth(); view.setLayoutParams(params); } }); }
/** 促销列表 */ private void initPromotionList() { List<Promotion> promotionList = product.getPromotionList(); if (null == promotionList) { return; } for (Promotion promotion : promotionList) { if (null == promotion) { continue; } View view = getLayoutInflater().inflate(R.layout.item_product_promotion_list, null); TextView type = (TextView) view.findViewById(R.id.item_product_promotin_list_type); if ("0".equals(promotion.getType())) { type.setText("满减"); type.setBackgroundResource(R.drawable.promotion_type_full_cut); } if ("1".equals(promotion.getType())) { type.setText("满包邮"); type.setBackgroundResource(R.drawable.promotion_type_full_baoyou); } if ("2".equals(promotion.getType())) { type.setBackgroundResource(R.drawable.promotion_type_full_cut); } TextView desc = (TextView) view.findViewById(R.id.item_product_promotin_list_desc); desc.setText(promotion.getDesc()); llytPromotionList.addView(view); } }
/** 服务列表 */ private void initServiceList() { List<ServiceDto> serviceList = product.getServiceList(); if (null == serviceList) { return; } for (ServiceDto service : serviceList) { View view = getLayoutInflater().inflate(R.layout.item_product_service_list, null); ((TextView) view.findViewById(R.id.item_product_service_list_name)) .setText(service.getContent()); llytServiceList.addView(view); } }
/** 评论列表 */ private void initCommentList() { TextView txtCommenterNum = (TextView) findViewById(R.id.layout_product_comment_commenter_num); TextView txtCommenterPoint = (TextView) findViewById(R.id.layout_product_comment_total_point); RatingBar ratingBar = (RatingBar) findViewById(R.id.layout_product_comment_ratingbar); LinearLayout llytContainer = (LinearLayout) findViewById(R.id.layout_product_comment_container); txtCommenterNum.setText("用户评价(" + product.getCommentCount() + "人)"); txtCommenterPoint.setText("综合评分:" + product.getCommentPoint()); ratingBar.setRating(product.getCommentPoint()); if (null == product.getCommentList() || 2 >= product.getCommentList().size()) { findViewById(R.id.layout_product_comment_more).setVisibility(View.GONE); return; } if (null != product.getCommentList()) { for (int i = 0; i < 2; i++) { Comment2 comment = product.getCommentList().get(i); if (null == comment) { return; } llytContainer.addView(creatCommentView(comment)); llytContainer.addView(getLayoutInflater().inflate(R.layout.line_gray_full, null)); } } }
private void showSkuPopupWindow(int action) { skuPopupWindow = new ProductSkuListPopupWindow(this, action, pop_layout, product.getSkuList()); skuPopupWindow.show(findViewById(R.id.pop_base_view)); }