Android簡單實(shí)現(xiàn)訂單模塊類APP的物流詳情頁

簡單實(shí)現(xiàn)物流詳情頁


當(dāng)在開發(fā)有訂單模塊類型的App時(shí)基本上都會(huì)用到物流詳情頁

大概看了下各大電商App的物流詳情頁, 其實(shí)大同小異都差不多是一種

可能也只是部分細(xì)節(jié)的不同

第三方庫

先看效果圖

example.png

Gradle配置

repositories { 
    maven { url "https://jitpack.io" }
} 
dependencies {
    compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.40'
}

BaseRecyclerViewAdapterHelper是一個(gè)封裝了RecyclerView自帶的Adapter的第三方庫


使用前先解決ScrollView嵌套RecyclerView的沖突
之前寫過一篇文章有說道這個(gè)問題

沖突解決文章

rv_logistics.setLayoutManager(new LinearLayoutManager(this));
//解決ScrollView嵌套R(shí)ecyclerView出現(xiàn)的系列問題
rv_logistics.setNestedScrollingEnabled(false);
rv_logistics.setHasFixedSize(true);

XML使用

draw_example.png
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="12dp">

    <LinearLayout
        android:layout_width="18dp"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:orientation="vertical">

        <View
            android:id="@+id/v_short_line"
            android:layout_width="1dp"
            android:layout_height="15dp"
            android:background="#E6E6E6" />

        <ImageView
            android:id="@+id/iv_new"
            android:layout_width="18dp"
            android:layout_height="18dp"
            android:scaleType="fitXY"
            android:src="@mipmap/icon_logistics_new" />

        <ImageView
            android:id="@+id/iv_old"
            android:layout_width="11dp"
            android:layout_height="11dp"
            android:scaleType="fitXY"
            android:src="@drawable/shape_gray_circle"
            android:visibility="gone" />

        <View
            android:id="@+id/v_long_line"
            android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:background="#E6E6E6" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_weight="1"
        android:orientation="vertical"
        android:paddingTop="11dp">

        <TextView
            android:id="@+id/tv_info"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#18C289"
            android:textSize="14sp" />

        <TextView
            android:id="@+id/tv_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:layout_marginTop="12dp"
            android:textColor="#18C289"
            android:textSize="12sp" />

        <View
            android:id="@+id/v_bottom_line"
            android:layout_width="match_parent"
            android:layout_height="1px"
            android:background="#E6E6E6" />
    </LinearLayout>
</LinearLayout>

JAVA使用(適配器代碼)

其實(shí)核心的使用方法就是控制控件的隱藏顯示

根據(jù)不同的條件來控制

public class LogisticsInfoAdapter extends BaseQuickAdapter<LogisticsInfoBean, BaseViewHolder> {
    private Context context;
    private List<LogisticsInfoBean> data;

    public LogisticsInfoAdapter(Context context, int layoutResId, @Nullable List<LogisticsInfoBean> data) {
        super(layoutResId, data);
        this.context = context;
        this.data = data;
    }

    @Override
    protected void convert(BaseViewHolder helper, LogisticsInfoBean item) {
        //獲取物流信息和物流時(shí)間的字體顏色, 最新的一條物流數(shù)據(jù)字體為綠色
        int newInfoColor = context.getResources().getColor(helper.getLayoutPosition() == 0 ? R.color.green : R.color.gray);
        //當(dāng)前item的索引==0 && 物流數(shù)據(jù)的數(shù)量大于1條   ->  顯示綠色大圓圈
        helper.setGone(R.id.iv_new, helper.getLayoutPosition() == 0 && data.size() > 1)
                //當(dāng)前item的索引!=0 && 物流數(shù)據(jù)的數(shù)量大于1條   ->  顯示灰色小圓圈
                .setGone(R.id.iv_old, helper.getLayoutPosition() != 0 && data.size() > 1)
                //當(dāng)前item的索引 != 0    ->  顯示圓點(diǎn)上面短一點(diǎn)的灰線
                .setVisible(R.id.v_short_line, helper.getLayoutPosition() != 0)
                //當(dāng)前item的索引 != 物流數(shù)據(jù)的最后一條    ->  顯示圓點(diǎn)下面長一點(diǎn)的灰線
                .setGone(R.id.v_long_line, helper.getLayoutPosition() != data.size() - 1)
                //當(dāng)前item的索引 != 物流數(shù)據(jù)的最后一條    ->  顯示物流時(shí)間下面的橫向的灰線
                .setGone(R.id.v_bottom_line, helper.getLayoutPosition() != data.size() - 1)
                .setTextColor(R.id.tv_info, newInfoColor)
                .setTextColor(R.id.tv_date, newInfoColor)
                //物流信息
                .setText(R.id.tv_info, item.getAcceptStation())
                //物流時(shí)間
                .setText(R.id.tv_date, item.getAcceptTime());
    }
}

Kotlin使用(適配器代碼)

class LogisticsInfoAdapter(var context: BaseActivity?, var data: ArrayList<LogisticsInfoBean>?)
    : BaseQuickAdapter<LogisticsInfoBean, BaseViewHolder>(R.layout.item_logistics, data) {
    override fun convert(helper: BaseViewHolder?, item: LogisticsInfoBean?) {
        //獲取物流信息和物流時(shí)間的字體顏色, 最新的一條物流數(shù)據(jù)字體為綠色
        val textColor = context?.getColorFromBase(if (helper?.layoutPosition == 0) R.color.green_18C289 else R.color.text_btn_gray)
        //當(dāng)前item的索引==0 && 物流數(shù)據(jù)的數(shù)量大于1條   ->  顯示綠色大圓圈
        helper?.setGone(R.id.iv_new, helper.layoutPosition == 0 && data?.size!! > 1)
                //當(dāng)前item的索引!=0 && 物流數(shù)據(jù)的數(shù)量大于1條   ->  顯示灰色小圓圈
                ?.setGone(R.id.iv_old, helper.layoutPosition != 0 && data?.size!! > 1)
                //當(dāng)前item的索引 != 0    ->  顯示圓點(diǎn)上面短一點(diǎn)的灰線
                ?.setVisible(R.id.v_short_line, helper.layoutPosition != 0)
                //當(dāng)前item的索引 != 物流數(shù)據(jù)的最后一條    ->  顯示圓點(diǎn)下面長一點(diǎn)的灰線
                ?.setGone(R.id.v_long_line, helper.layoutPosition != data?.size!! - 1)
                //當(dāng)前item的索引 != 物流數(shù)據(jù)的最后一條    ->  顯示物流時(shí)間下面的橫向的灰線
                ?.setGone(R.id.v_bottom_line, helper.layoutPosition != data?.size!! - 1)
                ?.setTextColor(R.id.tv_info, textColor!!)
                ?.setTextColor(R.id.tv_date, textColor!!)
                //物流信息
                ?.setText(R.id.tv_info, item?.acceptStation)
                //物流時(shí)間
                ?.setText(R.id.tv_date, item?.acceptTime)
    }
}

需要要看詳細(xì)的代碼看這里
github源碼地址 歡迎star、fork

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容