首先是布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/detail_back_img"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="10dp"
fresco:placeholderImage="@drawable/leftjiantou"
fresco:placeholderImageScaleType="centerInside"
fresco:roundAsCircle="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="商品详情"
android:textSize="20sp" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.youth.banner.Banner
android:id="@+id/detail_banner"
android:layout_width="match_parent"
android:layout_height="250dp"></com.youth.banner.Banner>
<TextView
android:id="@+id/detail_tv_price"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="aaaaaaa"
android:textColor="#f00"
android:textSize="18sp" />
<TextView
android:id="@+id/detail_tv_title"
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="aaaaaaa"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableTop="@drawable/lingdang"
android:gravity="center"
android:text="供应商" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableTop="@drawable/dianpu"
android:gravity="center"
android:text="店铺" />
<TextView
android:id="@+id/tv_shopping_cart"
android:text="购物车"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableTop="@drawable/souwcart" />
<TextView
android:id="@+id/tv_add_shopping_cart"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ffb700"
android:gravity="center"
android:text="加入购物车"
android:textColor="#fff" />
<TextView
android:id="@+id/tv_buy"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#f00"
android:gravity="center"
android:text="立即购买"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>
然后是activity
public class GoodsActivity extends AppCompatActivity implements ProductDetailsView { @BindView(R.id.detail_back_img) SimpleDraweeView detailBackImg; @BindView(R.id.detail_banner) Banner detailBanner; @BindView(R.id.detail_tv_price) TextView detailTvPrice; @BindView(R.id.detail_tv_title) TextView detailTvTitle; @BindView(R.id.tv_shopping_cart) TextView tvShoppingCart; @BindView(R.id.tv_add_shopping_cart) TextView tvAddShoppingCart; @BindView(R.id.tv_buy) TextView tvBuy; private int pid; private String uid; private GoodsPresenter goodsPresenter; private GoodsBean.DataBean data; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_goods); ButterKnife.bind(this); EventBus.getDefault().register(this); uid = (String) SharedPreferencesUtils.getParam(this, "uid", ""); initData(); } private void initData() { goodsPresenter = new GoodsPresenter(this); goodsPresenter.getGoods(pid); // goodsPresenter.getAddCarts(); } @Subscribe(threadMode = ThreadMode.MAIN, sticky = true) public void event(PidBean pidBean) { pid = pidBean.getPid(); } @Override protected void onDestroy() { super.onDestroy(); EventBus.getDefault().unregister(this); } @Override public void showView(GoodsBean productDetailBean) { data = productDetailBean.getData(); String[] images = data.getImages().split("\\|"); List<String> imagelist = new ArrayList<>(); for (int i = 0; i < images.length; i++) { imagelist.add(images[i]); } detailBanner.setImageLoader(new ImageLoader() { @Override public void displayImage(Context context, Object path, ImageView imageView) { imageView.setImageURI(Uri.parse((String) path)); } @Override public ImageView createImageView(Context context) { SimpleDraweeView simpleDraweeView = new SimpleDraweeView(context); return simpleDraweeView; } }); detailBanner.setImages(imagelist) .isAutoPlay(false) .setBannerStyle(BannerConfig.NUM_INDICATOR) .start(); detailTvPrice.setText("¥:" + data.getPrice()); detailTvTitle.setText(data.getTitle()); } @Override public void showAddCart(AddCartBean addCartBean) { Toast.makeText(this, addCartBean.getMsg(), Toast.LENGTH_SHORT).show(); } @Override public Context context() { return this; } @OnClick({R.id.detail_back_img, R.id.tv_shopping_cart, R.id.tv_add_shopping_cart, R.id.tv_buy}) public void onViewClicked(View view) { switch (view.getId()) { case R.id.detail_back_img: finish(); break; case R.id.tv_shopping_cart: if (!TextUtils.isEmpty(uid)){ startActivity(new Intent(GoodsActivity.this, ShopFragment.class)); } break; case R.id.tv_add_shopping_cart: if (!TextUtils.isEmpty(uid)){ goodsPresenter.addCart(uid, pid); } break; case R.id.tv_buy: EventBus.getDefault().postSticky(new PriceBean(data.getPrice())); startActivity(new Intent(GoodsActivity.this,OrderActivity.class)); break; } } }