From d3bb92290b8dec051f14011076bdd1a7e1b0a50b Mon Sep 17 00:00:00 2001 From: Administrator <895938232@qq.com> Date: Wed, 10 Nov 2021 17:27:11 +0800 Subject: [PATCH] Simple code2.0 --- .idea/.gitignore | 3 + .idea/dpdb.iml | 9 ++ .idea/encodings.xml | 6 + .idea/misc.xml | 6 + .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 + .../com/example/dxsdpdb/IndexFragment.java | 87 ++++++------ .../com/example/dxsdpdb/MainActivity.java | 88 ++++++++++++ .../com/example/dxsdpdb/MissionFragment.java | 126 ++++++++++++------ code/main/res/layout/bottom.xml | 13 +- code/main/res/layout/fragment_index.xml | 92 ++++++++++++- code/main/res/layout/fragment_mine.xml | 117 ++++++++++++++-- code/main/res/layout/fragment_mission.xml | 30 ++++- code/main/res/values/colors.xml | 3 +- 14 files changed, 487 insertions(+), 107 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/dpdb.iml create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/dpdb.iml b/.idea/dpdb.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/dpdb.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e208459 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..bdf028c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/code/main/java/com/example/dxsdpdb/IndexFragment.java b/code/main/java/com/example/dxsdpdb/IndexFragment.java index a09285d..a557d03 100644 --- a/code/main/java/com/example/dxsdpdb/IndexFragment.java +++ b/code/main/java/com/example/dxsdpdb/IndexFragment.java @@ -4,60 +4,63 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageButton; +import android.widget.Toast; import androidx.fragment.app.Fragment; -/** - * A simple {@link Fragment} subclass. - * Use the {@link IndexFragment#newInstance} factory method to - * create an instance of this fragment. - */ public class IndexFragment extends Fragment { - - // TODO: Rename parameter arguments, choose names that match - // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER - private static final String ARG_PARAM1 = "param1"; - private static final String ARG_PARAM2 = "param2"; - - // TODO: Rename and change types of parameters - private String mParam1; - private String mParam2; - - public IndexFragment() { - // Required empty public constructor - } - - /** - * Use this factory method to create a new instance of - * this fragment using the provided parameters. - * - * @param param1 Parameter 1. - * @param param2 Parameter 2. - * @return A new instance of fragment IndexFragment. - */ - // TODO: Rename and change types and number of parameters - public static IndexFragment newInstance(String param1, String param2) { - IndexFragment fragment = new IndexFragment(); - Bundle args = new Bundle(); - args.putString(ARG_PARAM1, param1); - args.putString(ARG_PARAM2, param2); - fragment.setArguments(args); - return fragment; - } - + private View view = null; + private Button submit_buttion,accept_button; + private ImageButton market_button,losing_button,college_button; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (getArguments() != null) { - mParam1 = getArguments().getString(ARG_PARAM1); - mParam2 = getArguments().getString(ARG_PARAM2); - } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_index, container, false); + if (view==null){ + view= inflater.inflate(R.layout.fragment_index,container,false); + submit_buttion = view.findViewById(R.id.raise_button); + accept_button = view.findViewById(R.id.accept_button); + market_button = view.findViewById(R.id.market_button); + losing_button = view.findViewById(R.id.losing_button); + college_button = view.findViewById(R.id.college_buttion); + initEvents(); + } + return view; + } + private void initEvents() { + View.OnClickListener onClickListener = new View.OnClickListener() { + public void onClick(View v) { + switch (v.getId()) { + case R.id.raise_button: + ; + break; + case R.id.accept_button: + ; + break; + case R.id.market_button: + Toast.makeText(getActivity(),"此功能暂未开放!",Toast.LENGTH_SHORT).show(); + break; + case R.id.losing_button: + Toast.makeText(getActivity(),"此功能暂未开放!",Toast.LENGTH_SHORT).show(); + break; + case R.id.college_buttion: + Toast.makeText(getActivity(),"此功能暂未开放!",Toast.LENGTH_SHORT).show(); + break; + + } + }}; + //设置三个 Tab 的点击事件 + submit_buttion.setOnClickListener(onClickListener); + accept_button.setOnClickListener(onClickListener); + market_button.setOnClickListener(onClickListener); + losing_button.setOnClickListener(onClickListener); + college_button.setOnClickListener(onClickListener); } } \ No newline at end of file diff --git a/code/main/java/com/example/dxsdpdb/MainActivity.java b/code/main/java/com/example/dxsdpdb/MainActivity.java index 474a1cd..228cb9f 100644 --- a/code/main/java/com/example/dxsdpdb/MainActivity.java +++ b/code/main/java/com/example/dxsdpdb/MainActivity.java @@ -1,14 +1,102 @@ package com.example.dxsdpdb; import android.os.Bundle; +import android.view.View; +import android.widget.LinearLayout; import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentTransaction; + +import java.util.ArrayList; +import java.util.List; public class MainActivity extends AppCompatActivity { + private List mFragments; + + private LinearLayout mIndexPage; + private LinearLayout mMissionPage; + private LinearLayout mMinePage; + +// private ImageButton mImgIndexPage; +// private ImageButton mImgMissionPage; +// private ImageButton mImgMinePage; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + //去除标题栏 + getSupportActionBar().hide(); setContentView(R.layout.activity_main); + initFragments(); //初始化数据 + initViews(); //初始化控件 + initEvents(); //初始化事件 + initFirstRun(0);//第一次运行初始化界面,第一个碎片 + } + + private void initFragments() { + mFragments = new ArrayList<>(); + //将四个 Fragment 加入集合中 + mFragments.add(new IndexFragment()); + mFragments.add(new MissionFragment()); + mFragments.add(new MineFragment()); + } + + private void initViews() { + mIndexPage = (LinearLayout) findViewById(R.id.id_index); + mMissionPage = (LinearLayout) findViewById(R.id.id_tab_mission); + mMinePage = (LinearLayout) findViewById(R.id.id_tab_mine); +// mImgIndexPage = (ImageButton) findViewById(R.id.id_tab_index_img); +// mImgMissionPage = (ImageButton) findViewById(R.id.id_tab_mission_img); +// mImgMinePage = (ImageButton) findViewById(R.id.id_tab_mine_img); + } + + private void initEvents() { + View.OnClickListener onClickListener = new View.OnClickListener() { + public void onClick(View v) { + //先将三个 ImageButton 置为蓝色 + resetBackgroud(); + //根据点击的 Tab 切换不同的页面及设置对应的 ImageButton 为白色 + switch (v.getId()) { + case R.id.id_index: selectTab(0); break; + case R.id.id_tab_mission: selectTab(1); break; + case R.id.id_tab_mine: selectTab(2); break; + } + }}; + //设置三个 Tab 的点击事件 + mIndexPage.setOnClickListener(onClickListener); + mMissionPage.setOnClickListener(onClickListener); + mMinePage.setOnClickListener(onClickListener); + } + private void resetBackgroud() { + mIndexPage.setBackgroundColor(getResources().getColor(R.color.blue)); + mMissionPage.setBackgroundColor(getResources().getColor(R.color.blue)); + mMinePage.setBackgroundColor(getResources().getColor(R.color.blue)); + } + private void selectTab(int i) { + //根据点击的 Tab 设置对应的 tab 为白色 + switch (i) { + case 0: mIndexPage.setBackgroundColor(getResources().getColor(R.color.blue0));break; + case 1: mMissionPage.setBackgroundColor(getResources().getColor(R.color.blue0));break; + case 2: mMinePage.setBackgroundColor(getResources().getColor(R.color.blue0));break; + } + //设置当前点击的 Tab 所对应的页面 + setCurrentFragment(i); + } + + private void setCurrentFragment(int i) + { + FragmentManager fm = getSupportFragmentManager(); + FragmentTransaction trans = fm.beginTransaction(); + trans.replace(R.id.frag_layout, mFragments.get(i)); + trans.commit(); + } + + private void initFirstRun(int i) + { + resetBackgroud(); //重置所有 Tab + selectTab(i); //显示第 i 个碎片 } } \ No newline at end of file diff --git a/code/main/java/com/example/dxsdpdb/MissionFragment.java b/code/main/java/com/example/dxsdpdb/MissionFragment.java index d0dddbc..ffb751e 100644 --- a/code/main/java/com/example/dxsdpdb/MissionFragment.java +++ b/code/main/java/com/example/dxsdpdb/MissionFragment.java @@ -1,63 +1,111 @@ package com.example.dxsdpdb; import android.os.Bundle; +import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.HorizontalScrollView; +import android.widget.RadioButton; +import android.widget.RadioGroup; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.viewpager.widget.ViewPager; -/** - * A simple {@link Fragment} subclass. - * Use the {@link MissionFragment#newInstance} factory method to - * create an instance of this fragment. - */ -public class MissionFragment extends Fragment { +public class MissionFragment extends Fragment implements ViewPager.OnPageChangeListener { - // TODO: Rename parameter arguments, choose names that match - // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER - private static final String ARG_PARAM1 = "param1"; - private static final String ARG_PARAM2 = "param2"; + private View view=null; // 碎片的布局实例 + private ViewPager viewPager; //内导航的碎片的容器 + private RadioGroup rgChannel=null; // 内导航由单选按钮组构成 + private HorizontalScrollView hvChannel=null; //单选按钮组可滚动动 + private String[] channelList = {"全部任务","待付款","待接受","待完成","已完成","已过期"}; //默认的内导航栏目 + private MissionFragmentAdapter adapter; //viewPager 的适配器 - // TODO: Rename and change types of parameters - private String mParam1; - private String mParam2; + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } public MissionFragment() { // Required empty public constructor } - /** - * Use this factory method to create a new instance of - * this fragment using the provided parameters. - * - * @param param1 Parameter 1. - * @param param2 Parameter 2. - * @return A new instance of fragment MissionFragment. - */ - // TODO: Rename and change types and number of parameters - public static MissionFragment newInstance(String param1, String param2) { - MissionFragment fragment = new MissionFragment(); - Bundle args = new Bundle(); - args.putString(ARG_PARAM1, param1); - args.putString(ARG_PARAM2, param2); - fragment.setArguments(args); - return fragment; + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + if(view==null){ + view=inflater.inflate(R.layout.fragment_mission, container, false); + viewPager=(ViewPager)view.findViewById(R.id.vpNewsList); + initViewPager(); //设置 ViewPager + rgChannel=(RadioGroup)view.findViewById(R.id.rgChannel); + hvChannel=(HorizontalScrollView)view.findViewById(R.id.hvChannel); + initTab(inflater); //初始化内导航标签 + rgChannel.setOnCheckedChangeListener( //单选按钮的监听事件响应 + new RadioGroup.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(RadioGroup group,int checkedId) { + //单击某个选项按钮时 viewPager 进行切换 + viewPager.setCurrentItem(checkedId); + } + }); + } + return view; } - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - if (getArguments() != null) { - mParam1 = getArguments().getString(ARG_PARAM1); - mParam2 = getArguments().getString(ARG_PARAM2); + private void initTab(LayoutInflater inflater){ + for(int i=0;i + android:gravity="center"> @@ -47,7 +46,7 @@ diff --git a/code/main/res/layout/fragment_index.xml b/code/main/res/layout/fragment_index.xml index 57a67a0..0c92c0c 100644 --- a/code/main/res/layout/fragment_index.xml +++ b/code/main/res/layout/fragment_index.xml @@ -6,9 +6,97 @@ tools:context=".IndexFragment"> - + android:orientation="vertical"> + + + + + + + + + + + + + + - - + + android:layout_height="wrap_content"> + + + + + + + + + + + + + - \ No newline at end of file + \ No newline at end of file diff --git a/code/main/res/layout/fragment_mission.xml b/code/main/res/layout/fragment_mission.xml index a87f2ca..3218550 100644 --- a/code/main/res/layout/fragment_mission.xml +++ b/code/main/res/layout/fragment_mission.xml @@ -1,14 +1,32 @@ - - - - \ No newline at end of file + android:layout_height="wrap_content"> + + + + + + + + \ No newline at end of file diff --git a/code/main/res/values/colors.xml b/code/main/res/values/colors.xml index 133c3a1..d7163db 100644 --- a/code/main/res/values/colors.xml +++ b/code/main/res/values/colors.xml @@ -7,5 +7,6 @@ #FF018786 #FF000000 #FFFFFFFF - #4169E1 + #B0E0E6 + #4169E1 \ No newline at end of file