1、内容:请根据课程实操实现APP门户界面框架设计,至少包含4个tab页,能实现tab页之间的点击切换;
2、技术:使用布局(layouts)和分段(fragment),对控件进行点击监听;
(没有做出点击图标改变颜色的效果)
此界面分为三个部分
top:界面最上方的wechat,可在layout使用textview部件居中展示该文字效果。
content:下面四个标签,能够根据底部功能栏的切换而随之切换。可以使用frameLayout实现该功能,在frameLayout中包含四个fragment部件对应四个功能栏即可。
bottom:在bottom版块中,进一步分析应将其水平划分为四个LinearLayout,在每一个LinearLayout中应该再垂直划分为两个LinearLayout
想设置的图标在阿里矢量图中可以免费下载
从所在目录中直接拖拽到drawable目录下就可以导入使用
代码 layoutactivity_main.xml
bottom.xml
四个fragment.xml
还有两个也差不多
top.xml
MainActivity.java
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements View.onClickListener {
private Fragment weixinFragment = new weixinFragment();
private Fragment weixinContacts = new weixinContacts();
private Fragment weixinLook = new weixinLook();
private Fragment weixinMeow = new weixinMeow();
private FragmentManager fragmentManager;
private View LinearLayout1,LinearLayout2,LinearLayout3,LinearLayout4;
private TextView textView1,textView2,textView3,textView4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
LinearLayout1 = findViewById(R.id.LinearLayout_weixinFragment);
LinearLayout2 = findViewById(R.id.LinearLayout_weixinContacts);
LinearLayout3 = findViewById(R.id.LinearLayout_weixinLook);
LinearLayout4 = findViewById(R.id.LinearLayout_weixinMeow);
textView1 = findViewById(R.id.textView1);
textView2 = findViewById(R.id.textView2);
textView3 = findViewById(R.id.textView3);
textView4 = findViewById(R.id.textView4);
LinearLayout1.setonClickListener(this);
LinearLayout2.setonClickListener(this);
LinearLayout3.setonClickListener(this);
LinearLayout4.setonClickListener(this);
textView1.setonClickListener(this);
textView2.setonClickListener(this);
textView3.setonClickListener(this);
textView4.setonClickListener(this);
initFragment();
showFragment(0);
}
private void initFragment(){
fragmentManager = getFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.add(R.id.content,weixinFragment);
transaction.add(R.id.content,weixinContacts);
transaction.add(R.id.content,weixinLook);
transaction.add(R.id.content,weixinMeow);
transaction.commit();
}
public void hideFragment(FragmentTransaction transaction){
transaction.hide(weixinFragment);
transaction.hide(weixinContacts);
transaction.hide(weixinLook);
transaction.hide(weixinMeow);
}
private void showFragment(int i){
FragmentTransaction transaction = fragmentManager.beginTransaction();
hideFragment(transaction);
switch (i){
case 0:
transaction.show(weixinFragment);
textView1.setText("聊天");
break;
case 1:
transaction.show(weixinContacts);
textView2.setText("联系人");
break;
case 2:
transaction.show(weixinLook);
textView3.setText("朋友圈");
break;
case 3:
transaction.show(weixinMeow);
textView4.setText("喵呜");
break;
default:
break;
}
transaction.commit();
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.LinearLayout_weixinFragment:
showFragment(0);
break;
case R.id.LinearLayout_weixinContacts:
showFragment(1);
break;
case R.id.LinearLayout_weixinLook:
showFragment(2);
break;
case R.id.LinearLayout_weixinMeow:
showFragment(3);
break;
default:
break;
}
}
}
界面展示
代码仓库
https://github.com/aedela/MyApp



