在本次作业中,我们需要设计和开发一个符合以下要求App的门户页面:
在本次实验中,我们主要采用以下技术:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
······<LinearLayoutandroid:id="@+id/id_tab_home"android:layout_width="0dp"android:layout_height="match_parent"android:layout_gravity="center"android:layout_weight="1"android:gravity="center"android:orientation="vertical"><ImageViewandroid:id="@+id/tab_iv_home"android:layout_width="match_parent"android:layout_height="wrap_content"android:adjustViewBounds="true"android:scaleType="centerCrop"android:src="@mipmap/ml23_16_9_removebg_preview" /><TextViewandroid:id="@+id/text_home"android:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center"android:text="首页"android:textSize="25sp" /></LinearLayout><LinearLayout······android:text="探索" />······ </LinearLayout><LinearLayout······ android:text="消息" />······ </LinearLayout><LinearLayout······android:text="我的" />······</LinearLayout></LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
&straintlayout.widget.ConstraintLayout xmlns:android=""xmlns:app=""xmlns:tools=""android:layout_width="match_parent"android:layout_height="match_parent">&lerview.widget.RecyclerViewandroid:id="@+id/recylerview"android:layout_width="match_parent"android:layout_height="match_parent"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" />
</straintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""android:layout_width="match_parent"android:layout_height="match_parent"><ListViewandroid:id="@+id/list_view"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="2"android:divider="@android:color/darker_gray"android:dividerHeight="1dp" /><ImageViewandroid:id="@+id/image_view"android:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="7"android:scaleType="fitCenter" /></LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><ImageViewandroid:id="@+id/imageView"android:layout_width="58dp"android:layout_height="match_parent"android:adjustViewBounds="true"android:scaleType="centerCrop"android:src="@mipmap/ml19" /><LinearLayoutandroid:layout_width="208dp"android:layout_height="match_parent"android:layout_gravity="center"android:layout_weight="1"android:gravity="center"android:orientation="vertical"><TextViewandroid:id="@+id/textView21"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:gravity="center"android:text="TextView"android:textColor="@color/black"android:textSize="20sp" /><TextViewandroid:id="@+id/textView22"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:gravity="center|left"android:text="TextView"android:textColor="#48514D"android:textSize="30sp" /></LinearLayout></LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
&straintlayout.widget.ConstraintLayout xmlns:android=""xmlns:app=""xmlns:tools=""android:id="@+id/linearLayout2"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="#CA8C8C"><TextViewandroid:id="@+id/textView3"android:layout_width="0dp"android:layout_height="wrap_content"android:gravity="center"android:text="还没有想好名字"android:textColor="@color/white"android:textSize="30sp"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" /></straintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><includeandroid:id="@+id/id_top"layout="@layout/top" /><FrameLayoutandroid:id="@+id/content1"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="1"android:background="#ECEEEE"></FrameLayout><includeandroid:id="@+id/id_buttom"layout="@layout/buttom" /></LinearLayout>
applicationhomework;
import ···public class MyAdapter extends RecyclerView.Adapter<MyAdapter.Myholder> {List<String> list1, list2;Context context1;public MyAdapter(List list_1, List list_2, Context context) {list1 = list_1;list2 = list_2;context1 = context;}@NonNull@Overridepublic Myholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {View view = LayoutInflater.from(context1).inflate(R.layout.item, parent, false);Myholder myholder = new Myholder(view);return myholder;}public void onBindViewHolder(@NonNull Myholder holder, int position) {View1.(position));View2.(position));}@Overridepublic int getItemCount() {return list1.size();}class Myholder extends RecyclerView.ViewHolder {TextView textView1, textView2;public Myholder(@NonNull View itemView) {super(itemView);textView1 = itemView.findViewById(View21);textView2 = itemView.findViewById(View22);}}
}
applicationhomework;
import ···public class Fragment1 extends Fragment {private Fragment1Binding fragment1Binding;ArrayList<String> list1 = new ArrayList<>();ArrayList<String> list2 = new ArrayList<>();@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {fragment1Binding = Fragment1Binding.inflate(inflater, container, false);View view = Root();setList();MyAdapter myAdapter = new MyAdapter(list1, list2, Context());lerview.setAdapter(myAdapter);LinearLayoutManager manager = new Context());manager.setOrientation(RecyclerView.VERTICAL);lerview.setLayoutManager(manager);return view;}private void setList() {for (int i = 1; i <= 11; i++) {list1.add("六边形战士:马龙");}list2.add("2022世锦赛男团冠军");list2.add("2021东京奥运会男单冠军");list2.add("2022东京奥运会男团冠军");list2.add("2020世界乒联总决赛冠军");list2.add("2019世锦赛男单冠军");list2.add("2019世锦赛男双冠军");list2.add("2018世锦赛男团冠军");list2.add("2017世锦赛男单冠军");list2.add("2016世锦赛男团冠军");list2.add("2016巴西奥运会男单冠军");list2.add("2016巴西奥运会男团冠军");}@Overridepublic void onDestroyView() {DestroyView();fragment1Binding = null;}
}
applicationhomework;import ···
public class MainActivity1Binding extends AppCompatActivity implements View.OnClickListener {Fragment fragment1, fragment2, fragment3, fragment4;private ActivityMain1Binding activityMain1Binding;FragmentManager fragmentManager;@Overrideprotected void onCreate(Bundle savedInstanceState) {Create(savedInstanceState);activityMain1Binding = ActivityMain1Binding.inflate(getLayoutInflater());View view = Root();setContentView(view);fragmentManager = getSupportFragmentManager();fragment1 = new Fragment1();fragment2 = new Fragment2();fragment3 = new Fragment3();fragment4 = new Fragment4();initial();fragmentshow(fragment1);activityMain1Binding.idButtom.idTabHome.setOnClickListener(this);activityMain1Binding.idButtom.idTabExplore.setOnClickListener(this);activityMain1Binding.idButtom.idTabMessage.setOnClickListener(this);activityMain1Binding.idButtom.idTabMy.setOnClickListener(this);}private void fragmentshow(Fragment fragment) {fragmenthide();FragmentTransaction ft = fragmentManager.beginTransaction().show(fragment);ftmit();}private void initial() {FragmentTransaction ft = fragmentManager.beginTransaction().t1.getId(), fragment1).t1.getId(), fragment2).t1.getId(), fragment3).t1.getId(), fragment4);ftmit();}private void fragmenthide() {FragmentTransaction ft = fragmentManager.beginTransaction().hide(fragment1).hide(fragment2).hide(fragment3).hide(fragment4);ftmit();}@Overridepublic void onClick(View view) {if (view == activityMain1Binding.idButtom.idTabHome)fragmentshow(fragment1);else if (view == activityMain1Binding.idButtom.idTabExplore)fragmentshow(fragment2);else if (view == activityMain1Binding.idButtom.idTabMessage)fragmentshow(fragment3);else if (view == activityMain1Binding.idButtom.idTabMy)fragmentshow(fragment4);}
}
Gitee完整源码
本文发布于:2024-02-02 18:26:17,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170686992645626.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |