矽谷商城第二版2--首頁模組,矽谷商城第二版2--

來源:互聯網
上載者:User

矽谷商城第二版2--首頁模組,矽谷商城第二版2--

1.fragment_home.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".home.fragment.HomeFragment">    <include        android:id="@+id/titlebar"        layout="@layout/titlebar" />    <android.support.v7.widget.RecyclerView        android:id="@+id/rv_home"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_below="@id/titlebar" />    <ImageButton        android:id="@+id/ib_top"        android:layout_width="40dp"        android:layout_height="40dp"        android:layout_alignParentBottom="true"        android:layout_alignParentRight="true"        android:layout_marginBottom="20dp"        android:layout_marginRight="20dp"        android:background="@drawable/top_btn"        android:visibility="gone" /></RelativeLayout>

2.RecyclerView中六種item類型:

  橫幅廣告  頻道 活動 秒殺 推薦 熱賣

3.橫幅廣告 

  Banner實現輪播

4.秒殺

HomeRecyclerViewAdapter中

public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {    .....    } else if (viewType == SECKILL) {        return new SeckillViewHolder(mLayoutInflater.inflate(R.layout.seckill_item, null), mContext);    }}

seckill_item.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="380dp"    android:layout_height="180dp"    android:background="#fff"    android:orientation="vertical"    android:padding="10dp">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content">        <ImageView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:src="@drawable/home_arrow_left_flash" />        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_marginLeft="10dp"            android:text="今日閃購 距·結束"            android:textColor="#000" />        <TextView            android:id="@+id/tv_time_seckill"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_marginLeft="10dp"            android:background="@drawable/time_shape"            android:padding="2dp"            android:text="00:00:00"            android:textColor="#fff" />        <TextView            android:id="@+id/tv_more_seckill"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="1"            android:drawablePadding="5dp"            android:drawableRight="@drawable/home_arrow_right"            android:gravity="end"            android:text="查看更多" />    </LinearLayout>    <android.support.v7.widget.RecyclerView        android:id="@+id/rv_seckill"        android:layout_width="match_parent"        android:layout_height="wrap_content" /></LinearLayout>

  

SeckillViewHolder  

class SeckillViewHolder extends RecyclerView.ViewHolder {    private TextView tvMore;    private RecyclerView recyclerView;    public Context mContext;    public SeckillViewHolder(View itemView, Context mContext) {        super(itemView);        tvTime = (TextView) itemView.findViewById(R.id.tv_time_seckill);        tvMore = (TextView) itemView.findViewById(R.id.tv_more_seckill);        recyclerView = (RecyclerView) itemView.findViewById(R.id.rv_seckill);        this.mContext = mContext;    }    public void setData(final ResultBean.SeckillInfoBean data) {        //設定時間        if (isFirst) {//                dt = (int) (Integer.parseInt(data.getEnd_time()) - System.currentTimeMillis());            dt = (int) (Integer.parseInt(data.getEnd_time()) - (Integer.parseInt(data.getStart_time())));            isFirst = false;        }        //設定RecyclerView        recyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));        SeckillRecyclerViewAdapter adapter = new SeckillRecyclerViewAdapter(mContext, data);        recyclerView.setAdapter(adapter);        //倒計時        handler.sendEmptyMessageDelayed(0, 1000);        //點擊事件        adapter.setOnSeckillRecyclerView(new SeckillRecyclerViewAdapter.OnSeckillRecyclerView() {            @Override            public void onClick(int position) {                ResultBean.SeckillInfoBean.ListBean listBean = data.getList().get(position);                String name = listBean.getName();                String cover_price = listBean.getCover_price();                String figure = listBean.getFigure();                String product_id = listBean.getProduct_id();                GoodsBean goodsBean = new GoodsBean(name, cover_price, figure, product_id);//                Intent intent = new Intent(mContext, GoodsInfoActivity.class);                intent.putExtra(GOODS_BEAN, goodsBean);                mContext.startActivity(intent);                // Toast.makeText(mContext, "position:" + position, Toast.LENGTH_SHORT).show();            }        });    }}

  

private boolean isFirst = true;    private TextView tvTime;    private int dt;    private Handler handler = new Handler() {        @Override        public void handleMessage(Message msg) {            if (msg.what == 0) {                dt = dt - 1000;                SimpleDateFormat sd = new SimpleDateFormat("HH:mm:ss");                tvTime.setText(sd.format(new Date(dt)));                handler.removeMessages(0);                handler.sendEmptyMessageDelayed(0, 1000);                if (dt == 0) {                    handler.removeMessages(0);                }            }        }    };

採用CountdownView實現秒殺倒計時的效果

 

 

github:https://github.com/ganchuanpu/Shopping

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.