Android练手完整项目app(三)商品分类+流式布局Tag

在这里插入图片描述
在这里插入图片描述

1.整体布局,结合项目(一)在FunctionFragment创建整体布局。搜索框布局应该include引入,这里我就没单独抽取。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns: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="60dp"
        android:gravity="center"
        android:background="@color/home_top_bg">
        <RelativeLayout
            android:id="@+id/search_part"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_gravity="center"
            android:layout_margin="10dp"
            android:background="@drawable/bg_search">

            <ImageView
                android:id="@+id/searchImg"
                android:layout_width="10dp"
                android:layout_height="10dp"
                android:layout_centerVertical="true"
                android:layout_marginLeft="12dp"
                android:src="@mipmap/home_search_icon" />

            <EditText
                android:id="@+id/inputData"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginLeft="7dp"
                android:layout_toRightOf="@+id/searchImg"
                android:background="@null"
                android:hint="请输入关键字进行搜索"
                android:imeOptions="actionSearch"
                android:maxLength="10"
                android:paddingLeft="3dp"
                android:singleLine="true"
                android:textColor="@color/black"
                android:textColorHint="@color/black"
                android:textSize="16sp" />
        </RelativeLayout>
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal">
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/fun_recy"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#F2F3F7"
            android:layout_weight="1"/>
        <FrameLayout
            android:id="@+id/fun_framelayout"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:background="@color/white"/>

    </LinearLayout>

</LinearLayout>

2.左侧列表适配器和item布局

public class FunRecyAdapter extends RecyclerView.Adapter<FunRecyAdapter.ViewHolder> {
    private Context context;
    private   List<Fun_Bean.DatasBean> data;

    public FunRecyAdapter(Context context,   List<Fun_Bean.DatasBean> data) {
        this.context = context;
        this.data = data;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.fun_recy_item, parent, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @SuppressLint("ResourceAsColor")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.itemView.setId(position);
        holder.tv.setText(data.get(position).getShowName());

        if(data.get(position).isCheck()){
            holder.itemView.setBackgroundResource(R.drawable.act_recy_bg);
            holder.tv.setTextColor(Color.parseColor("#FF6600"));

        }else{
            holder.itemView.setBackgroundColor(Color.parseColor("#DDDDDD"));
            holder.tv.setTextColor(Color.parseColor("#FF000000"));
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mSelectorListener.onSelect(view,position);
            }
        });

    }

    @Override
    public int getItemCount() {
        return data.size()==0?0:data.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{

        private final TextView tv;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.tv);
        }
    }
    public interface OnSelectorListener{
        void onSelect(View view,int position);
    }
    public void setOnSelectorListener(OnSelectorListener listener){
        mSelectorListener=listener;
    }
    private OnSelectorListener mSelectorListener;
}

fun_recy_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="60dp"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

</LinearLayout>

3.创建右侧具体分类列表fragement-FunRightFragment

public class FunRightFragment extends Fragment {

    private RecyclerView mRecy;
    private Fun_Bean.DatasBean info;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fun_right_fg, null);
        mRecy = view.findViewById(R.id.fun_right_fg_rcy);
        //得到数据
        info = (Fun_Bean.DatasBean) getArguments().getSerializable("info");
        initViews();
        return view;
    }
    private void initViews() {
        // 设置布局管理器
        mRecy.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        List<Fun_Bean.DatasBean.ItemDTO> item = info.getItem();
        // 实例化Adapter对象
        Fun_Right_recy_Adapter adapter = new Fun_Right_recy_Adapter(getActivity(), item);
        // 设置Adapter
        mRecy.setAdapter(adapter);
        adapter.notifyDataSetChanged();


  }
}

fun_right_fg.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/fun_right_fg_rcy"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

Fun_Right_recy_Adapter,右侧fragment里面列表的适配器,这个列表里面就是流式布局

public class Fun_Right_recy_Adapter extends RecyclerView.Adapter<Fun_Right_recy_Adapter.ViewHolder> {
    private Context context;
    private List<Fun_Bean.DatasBean.ItemDTO> data;

    public Fun_Right_recy_Adapter(Context context,   List<Fun_Bean.DatasBean.ItemDTO> data) {
        this.context = context;
        this.data = data;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.fun_right_fg_item, parent, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @SuppressLint("ResourceAsColor")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.tv_title.setText(data.get(position).getTitle());
        // flexbox布局动态添加标签
        List<Fun_Bean.DatasBean.ItemDTO.TabDTO> tags = data.get(position).getTab();
        for (int i = 0; i < tags.size(); i++) {
            String temp = tags.get(i).getQ();
            View tagView = LayoutInflater.from(context).inflate(R.layout.item_tag_cell, null, false);
            TextView tag = tagView.findViewById(R.id.tv_tag);
            tag.setText(temp);
            // 设置标签点击事件
            tag.setOnClickListener(view -> itemCellClicker.onItemClick(temp));
            holder.flexbox_layout.addView(tagView);
        }






    }

    @Override
    public int getItemCount() {
        return data.size()==0?0:data.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{

        private final TextView tv_title;
        private final FlexboxLayout flexbox_layout;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_title = itemView.findViewById(R.id.tv_title);
            flexbox_layout = itemView.findViewById(R.id.flexbox_layout);
        }
    }
    public interface ItemCellClicker{
        void onItemClick(String tag);
    }

    // 流式布局标签点击事件
    public ItemCellClicker itemCellClicker;
    // 设置点击事件回调
    public void setItemCellClicker(ItemCellClicker itemCellClicker){
        this.itemCellClicker = itemCellClicker;
    }
}


fun_right_fg_item.xml 右侧fragment列表的子布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="10dp">

    <TextView
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        android:id="@+id/tv_title"
        android:text="Hello android"
        android:textSize="20sp"
        android:textColor="@color/black"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <!--流式布局-->
    <com.google.android.flexbox.FlexboxLayout
        android:id="@+id/flexbox_layout"
        android:orientation="horizontal"
        app:flexWrap="wrap"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>

item_tag_cell.xml 是流式布局子布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="10dp">

    <TextView
        android:id="@+id/tv_tag"
        android:paddingHorizontal="12dp"
        android:gravity="center"
        android:background="@drawable/flow_item_bg"
        android:text="Hello android"
        android:textSize="20sp"
        android:textColor="@color/black"
        android:layout_width="wrap_content"
        android:layout_height="32dp"/>

</LinearLayout>

4.绑定适配,创建Fragment,自己写假数据

public class FunctionFragment extends Fragment {

    private RecyclerView mRecy;
    private FunRecyAdapter mAdater;
    FunRightFragment functionFragment;
    private FragmentTransaction fragmentTransaction;
    private Bundle mBundle;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.frg_function, container, false);

        return inflate;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
    }

    private void initView(View view) {
        mRecy = view.findViewById(R.id.fun_recy);
        mRecy.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        String response="创建个json。。。。自己写吧";
        Fun_Bean fun_bean = new Gson().fromJson(response, Fun_Bean.class);
        mAdater = new FunRecyAdapter(getActivity(), fun_bean.getData());
        mRecy.setAdapter(mAdater);
        fun_bean.getData().get(0).setCheck(true);

        //创建Fragment对象
        functionFragment = new FunRightFragment();
        fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.fun_framelayout, functionFragment);

        //传递数据到Fragment
        mBundle = new Bundle();
        mBundle.putSerializable("info", fun_bean.getData().get(0));
        functionFragment.setArguments(mBundle);
        fragmentTransaction.commit();

        mAdater.setOnSelectorListener((view1, position) -> {
            Fun_Bean.DatasBean datasBean = fun_bean.getData().get(position);
            for (int i = 0; i < fun_bean.getData().size(); i++) {
                if (fun_bean.getData().get(i).getShowName().equals(datasBean.getShowName())) {
                    fun_bean.getData().get(i).setCheck(true);
                } else {
                    fun_bean.getData().get(i).setCheck(false);
                }
            }
            mAdater.notifyDataSetChanged();
            //右侧fragment
            //创建Fragment对象
            functionFragment = new FunRightFragment();
            fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fun_framelayout, functionFragment);

            //传递数据到Fragment
            mBundle = new Bundle();
            mBundle.putSerializable("info", fun_bean.getData().get(position));
            functionFragment.setArguments(mBundle);
            fragmentTransaction.commit();
        });

    }
  //流式布局
    implementation 'com.google.android.flexbox:flexbox:3.0.0'

本分类模块,主要练习流式布局,常用于历史搜索及各类型分类

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
软件测试App项目练手是一种学习和提升软件测试技能的有效方式。通过参与App项目的测试,我们可以实际操作并了解软件测试的各个方面,包括需求分析、测试计划制定、测试环境搭建、测试用例设计、缺陷跟踪和报告等。 首先,软件测试App项目练手可以帮助我们学习需求分析的能力。通过与开发人员和项目经理进行沟通,我们可以理解和准确把握项目的需求,从而能够制定出合理的测试计划和设计出具有代表性的测试用例。 其次,练习软件测试App项目还可以帮助我们掌握测试环境搭建和配置的技巧。在开展测试之前,我们需要搭建相应的测试环境,并保证其与实际运行环境的一致性,以确保测试结果的准确性和可靠性。 此外,软件测试App项目练手过程中,我们还需要设计测试用例来验证软件的各个功能和模块。通过练习,我们可以提高测试用例设计的效率和准确性,并能够覆盖到所有可能的测试场景,以发现潜在的软件缺陷。 最后,软件测试App项目练手也可以帮助我们熟悉缺陷跟踪和报告的过程。在测试过程中,我们会遇到各种不同的缺陷,需要进行准确的缺陷跟踪和记录,并向开发人员提供详细和清晰的缺陷报告,以便他们能够及时修复。 总之,软件测试App项目练手是一个锻炼和提升软件测试技能的有效方法。通过参与项目的测试,我们可以学习需求分析、测试环境搭建、测试用例设计和缺陷跟踪等各个方面的知识和技巧,从而更好地应对和完成实际的软件测试工作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值