云炬Android开发笔记 17商品详情功能开发
閱讀目錄
1.商品詳情ui框架設(shè)計
1.1 自定義圓形控件
1.2 底部欄的布局
1.3 整體布局
2.商品詳情UI-MD風格伸縮漸變效果實現(xiàn)
2.1 ui的綁定
2.2 服務(wù)器中商品詳情頁的數(shù)據(jù)的取出
3.商品詳情頁的中間信息的完善
4. 商品詳情頁下部滑動Tab頁面的實現(xiàn)
4.2 填充的ImageDelegate和布局
4.4 商品詳情頁的ViewPager的適配器的設(shè)置
5.商品飛入購物車和邏輯梳理
5.1 動畫的依賴
1.商品詳情ui框架設(shè)計
【說明】點擊商品之后跳轉(zhuǎn)到商品的詳情頁面
?
1.1 自定義圓形控件 【源碼】自定義圓形textView控件:com.flj.latte.ui.widget.CircleTextView1 package com.flj.latte.ui.widget; 2 3 import android.content.Context; 4 import android.graphics.Canvas; 5 import android.graphics.Color; 6 import android.graphics.Paint; 7 import android.graphics.PaintFlagsDrawFilter; 8 import android.support.annotation.ColorInt; 9 import android.support.v7.widget.AppCompatTextView; 10 import android.util.AttributeSet; 11 12 13 public class CircleTextView extends AppCompatTextView { 14 15 private final Paint PAINT; 16 private final PaintFlagsDrawFilter FILTER; 17 18 public CircleTextView(Context context) { 19 this(context, null); 20 } 21 22 public CircleTextView(Context context, AttributeSet attrs) { 23 super(context, attrs); 24 PAINT = new Paint(); 25 FILTER = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); 26 PAINT.setColor(Color.WHITE); 27 PAINT.setAntiAlias(true); 28 } 29 30 public final void setCircleBackground(@ColorInt int color) { 31 PAINT.setColor(color); 32 } 33 34 @Override 35 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 36 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 37 final int width = getMeasuredWidth(); 38 final int height = getMaxHeight(); 39 final int max = Math.max(width, height); 40 setMeasuredDimension(max, max); 41 } 42 43 @Override 44 public void draw(Canvas canvas) { 45 canvas.setDrawFilter(FILTER); 46 canvas.drawCircle(getWidth() / 2, getHeight() / 2, 47 Math.max(getWidth(), getHeight()) / 2, PAINT); 48 super.draw(canvas); 49 } 50 }
回到頂部
1.2 底部欄的布局
【源碼】\d1nj4n\latte-ec\src\main\res\layout\layout_goods_detail_bottom.xml
?
1 <?xml version="1.0" encoding="utf-8"?> 2 <android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools" 4 android:id="@+id/ll_bottom" 5 android:layout_width="match_parent" 6 android:layout_height="50dp" 7 android:layout_alignParentBottom="true" 8 android:baselineAligned="true" 9 android:orientation="horizontal"> 10 11 <RelativeLayout 12 android:id="@+id/rl_favor" 13 android:layout_width="0dp" 14 android:layout_height="match_parent" 15 android:layout_weight="1" 16 android:background="@android:color/white" 17 android:paddingBottom="5dp"> 18 19 <com.joanzapata.iconify.widget.IconTextView 20 android:id="@+id/icon_favor" 21 android:layout_width="match_parent" 22 android:layout_height="wrap_content" 23 android:layout_centerHorizontal="true" 24 android:layout_marginTop="10dp" 25 android:gravity="center" 26 android:text="{fa-heart-o}" 27 android:textSize="20sp" /> 28 29 <android.support.v7.widget.AppCompatTextView 30 android:layout_width="match_parent" 31 android:layout_height="wrap_content" 32 android:layout_alignParentBottom="true" 33 android:layout_centerHorizontal="true" 34 android:gravity="center" 35 android:text="喜歡" 36 android:textSize="12sp" /> 37 38 </RelativeLayout> 39 40 <RelativeLayout 41 android:id="@+id/rl_shop_cart" 42 android:layout_width="0dp" 43 android:layout_height="match_parent" 44 android:layout_weight="1" 45 android:background="@android:color/white" 46 android:paddingBottom="5dp"> 47 48 <com.joanzapata.iconify.widget.IconTextView 49 android:id="@+id/icon_shop_cart" 50 android:layout_width="match_parent" 51 android:layout_height="wrap_content" 52 android:layout_centerHorizontal="true" 53 android:layout_marginTop="10dp" 54 android:gravity="center" 55 android:text="{fa-shopping-cart}" 56 android:textSize="20sp" /> 57 58 <android.support.v7.widget.AppCompatTextView 59 android:layout_width="match_parent" 60 android:layout_height="wrap_content" 61 android:layout_alignParentBottom="true" 62 android:layout_centerHorizontal="true" 63 android:gravity="center" 64 android:text="購物車" 65 android:textSize="12sp" /> 66 67 <com.flj.latte.ui.widget.CircleTextView 68 android:id="@+id/tv_shopping_cart_amount" 69 android:layout_width="20dp" 70 android:layout_height="20dp" 71 android:layout_alignEnd="@+id/icon_shop_cart" 72 android:layout_alignParentTop="true" 73 android:layout_alignRight="@+id/icon_shop_cart" 74 android:layout_marginRight="20dp" 75 android:layout_marginTop="2dp" 76 android:gravity="center" 77 android:textColor="@android:color/white" 78 android:textSize="12sp" 79 tools:ignore="RtlHardcoded" /> 80 81 </RelativeLayout> 82 83 <RelativeLayout 84 android:id="@+id/rl_add_shop_cart" 85 android:layout_width="0dp" 86 android:layout_height="match_parent" 87 android:layout_weight="2" 88 android:background="@android:color/holo_orange_dark" 89 android:gravity="center_horizontal"> 90 91 <android.support.v7.widget.AppCompatTextView 92 android:layout_width="match_parent" 93 android:layout_height="match_parent" 94 android:layout_centerInParent="true" 95 android:gravity="center" 96 android:text="加入購物車" 97 android:textColor="@android:color/white" /> 98 99 </RelativeLayout> 100 </android.support.v7.widget.LinearLayoutCompat>
回到頂部
1.3 整體布局
【源碼】d1nj4n\latte-ec\src\main\res\layout\delegate_goods_detail.xml
?
回到頂部
2.商品詳情UI-MD風格伸縮漸變效果實現(xiàn)
回到頂部
2.1 ui的綁定
【說明】首先取出控件;
【商品詳情頁面的設(shè)置和布局】
【點擊響應(yīng)】【點擊index頁面的商品的按鈕圖標的點擊響應(yīng)】商品的id進行了傳遞,此處id就是json字符串中的id值;
?
【詳情頁面的數(shù)據(jù)】
?
【完善商品詳情頁】綁定ui;
?
回到頂部
2.2 服務(wù)器中商品詳情頁的數(shù)據(jù)的取出
【數(shù)據(jù)的返回】初始化數(shù)據(jù);此處具有g(shù)oods_id的參數(shù);
【banner數(shù)據(jù)的取出】
?
?
?
?
?
?
回到頂部
3.商品詳情頁的中間信息的完善
【說明】布局使用的是frameLayout,內(nèi)部會塞一個fragment,即delegate;
【好處】可以降低耦合度,可以改變其中的內(nèi)容;
?
?
?
【新建fragment】
【布局】
?
1 <?xml version="1.0" encoding="utf-8"?> 2 <android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:background="@android:color/white" 6 android:orientation="vertical"> 7 8 <android.support.v7.widget.AppCompatTextView 9 android:id="@+id/tv_goods_info_title" 10 android:layout_width="match_parent" 11 android:layout_height="wrap_content" 12 android:layout_marginLeft="20dp" 13 android:layout_marginRight="20dp" 14 android:layout_marginTop="20dp" 15 android:textColor="@android:color/black" 16 android:textSize="18sp" /> 17 18 <android.support.v7.widget.AppCompatTextView 19 android:id="@+id/tv_goods_info_desc" 20 android:layout_width="match_parent" 21 android:layout_height="wrap_content" 22 android:layout_marginLeft="20dp" 23 android:layout_marginRight="20dp" 24 android:layout_marginTop="5dp" 25 android:textSize="16sp" /> 26 27 <android.support.v7.widget.LinearLayoutCompat 28 android:layout_width="match_parent" 29 android:layout_height="wrap_content" 30 android:orientation="horizontal"> 31 32 <android.support.v7.widget.AppCompatTextView 33 android:layout_width="wrap_content" 34 android:layout_height="wrap_content" 35 android:layout_marginLeft="20dp" 36 android:layout_marginTop="10dp" 37 android:text="¥" 38 android:textColor="@color/app_main" 39 android:textSize="20sp" /> 40 41 <android.support.v7.widget.AppCompatTextView 42 android:id="@+id/tv_goods_info_price" 43 android:layout_width="wrap_content" 44 android:layout_height="wrap_content" 45 android:layout_marginTop="10dp" 46 android:text="1299" 47 android:textColor="@color/app_main" 48 android:textSize="20sp" /> 49 </android.support.v7.widget.LinearLayoutCompat> 50 51 </android.support.v7.widget.LinearLayoutCompat>
【傳遞服務(wù)器中的data數(shù)據(jù)】
?
?
【取出數(shù)據(jù)值】
?
【設(shè)置數(shù)據(jù)值】
?
?
?
?
回到頂部
4. 商品詳情頁下部滑動Tab頁面的實現(xiàn)
?
?
【需要將viewPager和TabLayout相應(yīng)的adapter中將數(shù)據(jù)進行轉(zhuǎn)化】達到映射數(shù)據(jù)和滑動變換的效果;
?
【傳遞數(shù)據(jù)】
?
?
【數(shù)據(jù)適配器--數(shù)據(jù)的取出】
?
?
?
?
?
回到頂部
4.2 填充的ImageDelegate和布局
【數(shù)據(jù)為空】當數(shù)據(jù)為空的時候,在頁面中使用fragment進行填充,有利于解耦;
?
?
?
【使用recycleView布局處理下半部的數(shù)據(jù)】
?
【完善】
【正確的寫法】上面的寫法不正確;
?
【初始化images】fragment天生支持StringarrayList;此處沒有進行轉(zhuǎn)化,處理簡單;
?
?
【recycleView中的item的布局】
【recycleView的數(shù)據(jù)適配器】
【使用ImageDelegate】
?
?
?
回到頂部
4.4 商品詳情頁的ViewPager的適配器的設(shè)置
?
?
?
回到頂部
5.商品飛入購物車和邏輯梳理
回到頂部
5.1 動畫的依賴
【貝塞爾動畫】使用別人的貝塞爾的動畫庫,經(jīng)過了修改;
?
【源碼】d1nj4n\latte-ui\src\main\java\com\flj\latte\ui\animation\BezierAnimation.java
?
?
?
【添加購物車的點擊事件】
?
【】圖片的url需要創(chuàng)建出來,獲取值;同樣 ,count值也需要處理;
?
?
【添加動畫】
?
?
?
?
?
?
?
?
【BUG】添加購物車之后沒有效果
?
?
?
?
【增加服務(wù)器返回數(shù)據(jù)的判斷】在真實的環(huán)境中返回的數(shù)據(jù)是很多的,不是簡單的true;
?
?
【效果】在加入購物車之后返回了服務(wù)器設(shè)置的值;
?
?
總結(jié)
以上是生活随笔為你收集整理的云炬Android开发笔记 17商品详情功能开发的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 云炬Android开发笔记 16附加功
- 下一篇: 如何高效率学Web前端 怎么规划前端学习