\"在这里插入图片描述\"
clolor颜色

<color name=\"white\">#FFFFFF</color> <!-- 白色 -->
    <color name=\"black\">#000000</color> <!-- 黑色 -->
    <color name=\"thinblue\">#4186c9</color> <!-- 淡蓝色 -->
    <color name=\"transparent\">#00000000</color> <!-- 透明 -->
    <color name=\"thingray\">#dae8f5</color> <!-- 淡灰色 -->
    <color name=\"thinwhite\">#c6daf0</color> <!-- 浅白色 -->
    <color name=\"gray\">#ececec</color> <!-- 灰色 -->
    <color name=\"grayblack\">#999999</color> <!-- 灰黑色 -->
    <color name=\"commonblack\">#585858</color> <!-- 一般使用的黑色 -->
    <color name=\"line_color\">#d8d8d8</color> <!-- 单调的黑色 -->
    <color name=\"radiocolor\">#858a8e</color> <!-- 按钮颜色 -->
    <color name=\"custom_gray\">#656565</color> <!-- 通用灰 -->
    <color name=\"list_black\">#d0d0d0</color> <!-- 分隔线黑 -->
    <color name=\"fontblack\">#4f4f4f</color> <!-- 字体颜色 -->
    <color name=\"fontgray\">#5c5c5c</color> <!-- 字体灰 -->
    <color name=\"graybg\">#efefef</color>
    <color name=\"gray_bg\">#fbfbfb</color> <!-- 事件详情页信息背景 -->
    <color name=\"blackgray\">#E5E5E5</color> <!-- 深灰 -->
    <color name=\"pure_gray\">#f2f2f2</color> <!-- 纯色灰 -->
    <color name=\"set_font_color\">#686868</color>
    <color name=\"set_ _color\">#9a9a9a</color>
    <color name=\"set_account_color\">#57a6d8</color>
    <color name=\"center_item_color\">#575757</color>
    <color name=\" bar_color\">#4bc1d2</color>
    <color name=\"set_line\">#e4e4e4</color>
    <color name=\"blue\">#145fa6</color> <!-- 蓝色 -->
    <color name=\"login_bg\">#4cb3e8</color>
    <color name=\"hintcolor\">#cdcdcd</color>
    <color name=\"tb_color\">#f8f8f8</color>
    <color name=\"center_checked_no_color\">#909090</color>
    <color name=\"msg_font_color\">#555555</color>
    <color name=\"mark_red\">#ff4040</color> <!-- 红色 -->
    <color name=\"gray_text\">#666666</color>
    <color name=\"topic_text_color\">#767676</color>
    <color name=\"filter_bg_color\">#00FBFF</color>
    <color name=\"gray_thin\">#adadad</color>
    <color name=\"topic_name_color\">#6db3be</color>
    <color name=\"topic_reply_color\">#a9a9a9</color>
    <color name=\"even_city_tui_color\">#777678</color>
    <color name=\"even_near_color\">#f2f1f1</color>
    <color name=\"even_near_small_color\">#dfdfdf</color>
    <color name=\"even_footer_color\">#989696</color>
    <color name=\"banner_join_press_color\">#d4ecf1</color>
    <color name=\"tb_text_color\">#4f423a</color>
    <color name=\"register_btn_color\">#7ed321</color>
    <color name=\"topic_reply_time_color\">#9b9b9b</color>

    <!-- 播的字体颜色 -->
    <color name=\"bo_small_text_color\">#CCCCCC</color>
    <color name=\"bo_text_hint_color\">#A4A4A4</color>
    <color name=\"body_text_1\">#ff000000</color>
    <color name=\"body_text_2\">#99000000</color>
    <color name=\"body_text_disabled\">#66000000</color>
    <color name=\"body_text_1_inverse\">#ffffffff</color>
    <color name=\"body_text_2_inverse\">#99ffffff</color>
    <color name=\"accent_1\">#ff29549f</color>
    <color name=\"hyper \">#ffff549f</color>
    <color name=\"background_1\">#ffffffff</color>
    <color name=\"whats_on_separator\">#4d000000</color>
    <color name=\"all_track_color\">#ff222222</color>
    <color name=\"block_column_1\">#ff0fabff</color>
    <color name=\"block_column_2\">#ffdf1831</color>
    <color name=\"block_column_3\">#ff009939</color>
    <color name=\"umeng_fb_color_btn_pressed\">#1495F7</color>
    <color name=\"umeng_fb_color_btn_normal\">#333333</color>
    <color name=\"actionbar_background_start\">#3A5FCD</color>
    <color name=\"actionbar_background_end\">#27408B</color>

主界面 分类

<?  version=\"1.0\" encoding=\"utf-8\"?>
<LinearLayout  ns:android=\"http://schemas.android.com/apk/res/android\"
    android:layout_width=\"match_parent\"
    android:layout_height=\"match_parent\"
    android:orientation=\"vertical\">
    <LinearLayout
        android:layout_width=\"match_parent\"
        android:layout_height=\"match_parent\"
        android:layout_weight=\"1\"
        android:orientation=\"horizontal\">
        <android.support.v7.widget.RecyclerView
            android:background=\"#66CD00	\"
            android:id=\"@+id/left_recycler\"
            android:layout_width=\"100dp\"
            android:layout_height=\"match_parent\">

        </android.support.v7.widget.RecyclerView>
        <android.support.v7.widget.RecyclerView
            android:id=\"@+id/right_recycler\"
            android:layout_width=\"match_parent\"
            android:layout_height=\"match_parent\">

        </android.support.v7.widget.RecyclerView>
    </LinearLayout>

    <RelativeLayout
        android:layout_width=\"match_parent\"
        android:layout_height=\"80dp\">

        <ImageView
            android:id=\"@+id/shop_car_image\"
            android:layout_width=\"wrap_content\"
            android:layout_height=\"wrap_content\"
            android:layout_centerVertical=\"true\"
            android:layout_marginLeft=\"10dp\" />
        <TextView
            android:id=\"@+id/goods_sum_price\"
            android:layout_width=\"wrap_content\"
            android:layout_height=\"wrap_content\"
            android:layout_alignParentRight=\"true\"
            android:text=\"价格:\"
            android:layout_marginLeft=\"20dp\"
            android:layout_centerVertical=\"true\"/>

        <TextView
            android:id=\"@+id/goods_number\"
            android:layout_width=\"30dp\"
            android:layout_height=\"30dp\"
            android:textSize=\"10sp\"
            android:gravity=\"center\"
            android:layout_marginLeft=\"-10dp\"
            android:layout_alignParentTop=\"true\"
            android:layout_toEndOf=\"@+id/shop_car_image\"
            android:text=\"7\" />
    </RelativeLayout>
</LinearLayout>

values中的arrays

<?  version=\"1.0\" encoding=\"utf-8\"?>
<resources>
    <string-array name=\"anim_type\">
        <item>fade</item>
        <item>slide </item>
        <item>rotate</item>
        <item>scale</item>
    </string-array>
</resources>

左边的 布局

<?  version=\"1.0\" encoding=\"utf-8\"?>
<LinearLayout  ns:android=\"http://schemas.android.com/apk/res/android\"
    android:layout_width=\"match_parent\"
    android:layout_height=\"match_parent\"
    android:orientation=\"vertical\">
    <TextView
        android:id=\"@+id/left_text\"
        android:layout_width=\"100dp\"
        android:layout_height=\"50dp\"
        android:textSize=\"16sp\"
        android:gravity=\"center\"
        android:textColor=\"#f00\"
        android:text=\"aa\" />
</LinearLayout>

右边的 布局

<?  version=\"1.0\" encoding=\"utf-8\"?>
<LinearLayout  ns:android=\"http://schemas.android.com/apk/res/android\"
    android:layout_width=\"match_parent\"
    android:layout_height=\"match_parent\"
    android:orientation=\"horizontal\">
    <ImageView
        android:id=\"@+id/image\"
        android:layout_width=\"100dp\"
        android:layout_height=\"wrap_content\"
        android:adjustViewBounds=\"true\"
        android:minHeight=\"50dp\"
        android:layout_alignParentLeft=\"true\"
        android:src=\"@mipmap/ic_launcher\"/>

    <TextView
        android:id=\"@+id/text\"
        android:layout_toRightOf=\"@+id/image\"
        android:layout_width=\"match_parent\"
        android:layout_height=\"wrap_content\"
        android:layout_marginTop=\"10dp\"
        android:text=\"aa\"
        android:padding=\"10dp\"/>
    <TextView
        android:id=\"@+id/text_price\"
        android:layout_toRightOf=\"@+id/image\"
        android:layout_below=\"@+id/text\"
        android:layout_width=\"match_parent\"
        android:layout_height=\"wrap_content\"
        android:layout_marginTop=\"10dp\"
        android:text=\"价格\"
        android:padding=\"10dp\"/>

    <com.example.demo4.http.AddSubLayout
        android:id=\"@+id/add_sub_layout\"
        android:layout_width=\"wrap_content\"
        android:layout_height=\"wrap_content\"
        android:layout_alignParentRight=\"true\"
        android:layout_alignParentBottom=\"true\"
        android:layout_marginRight=\"20dp\"
        android:layout_marginBottom=\"20dp\">

    </com.example.demo4.http.AddSubLayout>
</LinearLayout>

主页面的java代码

public class three_frag extends Fragment implements CallBacks<List<Shop>> {

    private TextView mSumPrice;
    private TextView mCount;
    private RecyclerView mLeftRecycler,mRightRecycler;
    private LeftAdapter mLeftAdapter;
    private RightAdapter mRightAdapter;
    private CartPresenter cartPresenter = new CartPresenter(this);
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.item_three,container,false);
        mSumPrice = view.findViewById(R.id.goods_sum_price);
        mCount = view.findViewById(R.id.goods_number);
        mLeftRecycler = view.findViewById(R.id.left_recycler);
        mRightRecycler = view.findViewById(R.id.right_recycler);

        mLeftRecycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRightRecycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        mLeftAdapter = new LeftAdapter();
        mLeftAdapter.setOnItemClickListenter(new LeftAdapter.OnItemClickListenter() {
            @Override
            public void onItemClick(Shop shop) {
                mRightAdapter.clearList();
                mRightAdapter.addAll(shop.getList());
                mRightAdapter.notifyDataSetChanged();
            }
        });
        mLeftRecycler.setAdapter(mLeftAdapter);
        mRightAdapter=new RightAdapter();
        mRightAdapter.setOnNumListener(new RightAdapter.OnNumListener() {
            @Override
            public void onNum() {
                calculatePrice(mLeftAdapter.getList());
            }
        });
        mRightRecycler.setAdapter(mRightAdapter);

        cartPresenter.requestData();
        return view;
    }

    private void calculatePrice(List<Shop> list) {
        double totalPrice=0;
        int totalNum=0;
        for (int i=0;i<list.size();i++){
            Shop shop=list.get(i);
            for (int j=0;j<shop.getList().size();j++){
                Goods goods=shop.getList().get(j);
                totalPrice=totalPrice+goods.getNum()*goods.getPrice();
                totalNum+=goods.getNum();
            }
        }
        mSumPrice.setText(\"价格:\"+totalPrice);
        mCount.setText(\"\"+totalNum);
    }

    @Override
    public void success(List<Shop> data) {
        calculatePrice(data);//计算价格和数量
        mLeftAdapter.addAll(data);
        Shop shop=data.get(1);
        shop.setTextColor(0xff000000);
        shop.setBackground(R.color.white);
        mRightAdapter.addAll(shop.getList());
        mLeftAdapter.notifyDataSetChanged();
        mRightAdapter.notifyDataSetChanged();
    }

    @Override
    public void fail(Result result) {
        Toast.makeText(getActivity(), result.getCode() + \"   \" + result.getMsg(), Toast.LENGTH_LONG).show();
    }
}

左边的Adapter

public class LeftAdapter extends RecyclerView.Adapter<LeftAdapter.MyHolder> {
    private List<Shop> mList=new ArrayList<>();
    public void addAll(List<Shop> list){
        mList.addAll(list);
    }
    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=View.inflate(parent.getContext(), R.layout.recycler_left_item,null);
        MyHolder myHolder=new MyHolder(view);
        return myHolder;
    }

    @Override
    public void onBindViewHolder(MyHolder holder, int position) {
        final Shop shop=mList.get(position);
        holder.text.setText(shop.getSellerName());
        holder.text.setBackgroundResource(shop.getBackground());
        holder.text.setTextColor(shop.getTextColor());
        holder.itemView.set Listener(new View. Listener() {
            @Override
            public void  (View v) {
                for (int j = 0; j <mList.size() ; j++) {
                    mList.get(j).setTextColor(0xffffffff);
                    mList.get(j).setBackground(R.color.grayblack);
                }
                shop.setBackground(R.color.white);
                shop.setTextColor(0xff000000);
                notifyDataSetChanged();
                onItemClickListenter.onItemClick(shop);//切换右边的列表
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }
    public List<Shop> getList(){
        return mList;
    }

    public class MyHolder extends RecyclerView.ViewHolder {
        TextView text;
        public MyHolder(View itemView) {
            super(itemView);
            text = itemView.findViewById(R.id.left_text);
        }
    }
    private OnItemClickListenter onItemClickListenter;

    public void setOnItemClickListenter(OnItemClickListenter onItemClickListenter) {
        this.onItemClickListenter = onItemClickListenter;
    }
    public interface OnItemClickListenter{
        void onItemClick(Shop shop);
    }
}

右边的Adapter

public class RightAdapter extends RecyclerView.Adapter<RightAdapter.ChildHolder> {
    private List<Goods> mList = new ArrayList<>();

    public void addAll(List<Goods> list) {
        mList.addAll(list);
    }
    @Override
    public ChildHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=View.inflate(parent.getContext(), R.layout.recycler_right_item,null);
        ChildHolder myHolder=new ChildHolder(view);
        return myHolder;
    }

    @Override
    public void onBindViewHolder(ChildHolder holder, int position) {
        final Goods goods=mList.get(position);
        holder.text.setText(goods.get ());
        holder.price.setText(\"单价:\"+goods.getPrice());
        String imageurl = \"https\" + goods.getImages().split(\"https\")[1];
        imageurl=imageurl.substring(0,imageurl.lastIndexOf(\".jpg\")+\".jpg\".length());
        Glide.with(DTApplication.getInstance()).load(imageurl).into(holder.image);
        holder.addSub.setCount(goods.getNum());
        holder.addSub.setAddSubListener(new AddSubLayout.AddSubListener() {
            @Override
            public void addSub(int count) {
                goods.setNum(count);
                onNumListener.onNum();
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }
    public void clearList(){
        mList.clear();
    }
    public class ChildHolder extends RecyclerView.ViewHolder {
        TextView text;
        TextView price;
        ImageView image;
        AddSubLayout addSub;
        public ChildHolder(View itemView) {
            super(itemView);
            text = itemView.findViewById(R.id.text);
            price = itemView.findViewById(R.id.text_price);
            image = itemView.findViewById(R.id.image);
            addSub = itemView.findViewById(R.id.add_sub_layout);
        }
    }
    private OnNumListener onNumListener;

    public void setOnNumListener(OnNumListener onNumListener) {
        this.onNumListener = onNumListener;
    }

    public interface OnNumListener{
        void onNum();
    }
}

收藏 打印