ll_address.setOnClickListener(this);
ll_friend.setOnClickListener(this);
ll_setting.setOnClickListener(this);
ll_set.setOnClickListener(this);
//设置ViewPager滑动监听
viewPager.setOnPageChangeListener(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
// 底部菜单5个Linearlayout
this.ll_home = findViewById(R.id.ll_home);
this.ll_address = findViewById(R.id.ll_address);
this.ll_friend = findViewById(R.id.ll_friend);
this.ll_setting = findViewById(R.id.ll_setting);
this.ll_set= findViewById(R.id.ll_set);
// 底部菜单5个菜单标题
this.tv_home = findViewById(R.id.tv_home);
this.tv_address = findViewById(R.id.tv_address);
this.tv_friend = findViewById(R.id.tv_friend);
this.tv_setting = findViewById(R.id.tv_setting);
this.tv_set= findViewById(R.id.tv_set);
// 中间内容区域ViewPager
this.viewPager = findViewById(R.id.vp_content);
// 适配器
View page_01 = View.inflate(HomeActivity.this, R.layout.page_01, null);
View page_02 = View.inflate(HomeActivity.this, R.layout.page_02, null);
View page_03 = View.inflate(HomeActivity.this, R.layout.page_03, null);
View page_04 = View.inflate(HomeActivity.this, R.layout.page_04, null);
View page_05 = View.inflate(HomeActivity.this, R.layout.page_05, null);
views = new ArrayList<>();
views.add(page_01);
views.add(page_02);
views.add(page_03);
views.add(page_04);
views.add(page_05);
this.adapter = new ContentAdapter(views);
viewPager.setAdapter(adapter);
initEvent();
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.ll_home:
tv_home.setTextColor(0xff1B940A);
viewPager.setCurrentItem(0);
break;
case R.id.ll_address:
tv_address.setTextColor(0xff1B940A);
viewPager.setCurrentItem(1);
break;
case R.id.ll_friend:
tv_friend.setTextColor(0xff1B940A);
viewPager.setCurrentItem(2);
break;
case R.id.ll_setting:
tv_setting.setTextColor(0xff1B940A);
viewPager.setCurrentItem(3);
break;
case R.id.ll_set:
tv_set.setTextColor(0xff1B940A);
viewPager.setCurrentItem(4);
default:
break;
}
}
private void restartBotton() {
// TextView置为白色
tv_home.setTextColor(0xffffffff);
tv_address.setTextColor(0xffffffff);
tv_friend.setTextColor(0xffffffff);
tv_setting.setTextColor(0xffffffff);
tv_set.setTextColor(0xffffffff);
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
restartBotton();
//当前view被选择的时候,改变底部菜单图片,文字颜色
switch (position) {
case 0:
tv_home.setTextColor(0xff1B940A);
break;
case 1:
tv_address.setTextColor(0xff1B940A);
break;
case 2:
tv_friend.setTextColor(0xff1B940A);
break;
case 3:
tv_setting.setTextColor(0xff1B940A);
break;
case 4:
tv_set.setTextColor(0xff1B940A);
break;
default:
break;
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
}
有报红的先不用理它。
(2)activity_home.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
tools:context=“com.example.myclient.HomeActivity”>
<LinearLayout
android:layout_width=“wrap_content”
android:layout_height=“match_parent”
android:gravity=“center”
android:orientation=“vertical”>
<androidx.viewpager.widget.ViewPager
android:id=“@+id/vp_content”
android:layout_width=“match_parent”
android:background=“#ffffff”
android:layout_height=“0dp”
android:layout_weight=“1” >
</androidx.viewpager.widget.ViewPager>
(3)activity_bottom.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“35dp”
android:background=“#CBB4F5” >
<LinearLayout
android:id=“@+id/ll_home”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:orientation=“vertical” >
<ImageView
android:id=“@+id/iv_home”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
/>
<TextView
android:id=“@+id/tv_home”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“页面1”
android:textSize=“20dp”
android:textColor=“#1B940A”
android:textStyle=“bold” />
<LinearLayout
android:id=“@+id/ll_address”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:orientation=“vertical” >
<ImageView
android:id=“@+id/iv_address”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
/>
<TextView
android:id=“@+id/tv_address”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“页面2”
android:textColor=“#ffffff”
android:textSize=“20dp”
android:textStyle=“bold” />
<LinearLayout
android:id=“@+id/ll_friend”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:orientation=“vertical” >
<ImageView
android:id=“@+id/iv_friend”
android:layout_width=“53dp”
android:layout_height=“match_parent”
/>
<TextView
android:id=“@+id/tv_friend”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“页面3”
android:textSize=“20dp”
android:textColor=“#ffffff”
android:textStyle=“bold” />
<LinearLayout
android:id=“@+id/ll_setting”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:orientation=“vertical” >
<ImageView
android:id=“@+id/iv_setting”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
/>
<TextView
android:id=“@+id/tv_setting”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“页面4”
android:textColor=“#ffffff”
android:textSize=“20dp”
android:textStyle=“bold” />
<LinearLayout
android:id=“@+id/ll_set”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:gravity=“center”
android:orientation=“vertical” >
<ImageView
android:id=“@+id/iv_set”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
/>
<TextView
android:id=“@+id/tv_set”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“页面5”
android:textColor=“#ffffff”
android:textSize=“20dp”
android:textStyle=“bold” />
(4)回到HomeActivity.java,会看到ContentAdapter报红,这里新建一个ContentAdapter.java类
public class ContentAdapter extends PagerAdapter {
private List views;
public ContentAdapter(List views) {
this.views = views;
}
@Override
public int getCount() {
return views.size();
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
View view = views.get(position);
container.addView(view);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView(views.get(position));
}
}
最后
今天关于面试的分享就到这里,还是那句话,有些东西你不仅要懂,而且要能够很好地表达出来,能够让面试官认可你的理解,例如Handler机制,这个是面试必问之题。有些晦涩的点,或许它只活在面试当中,实际工作当中你压根不会用到它,但是你要知道它是什么东西。
最后在这里小编分享一份自己收录整理上述技术体系图相关的几十套腾讯、头条、阿里、美团等公司20年的面试题,把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分。
还有 高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料 帮助大家学习提升进阶,也节省大家在网上搜索资料的时间来学习,也可以分享给身边好友一起学习。
【Android核心高级技术PDF文档,BAT大厂面试真题解析】
【算法合集】
【延伸Android必备知识点】
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!
}
}
最后
今天关于面试的分享就到这里,还是那句话,有些东西你不仅要懂,而且要能够很好地表达出来,能够让面试官认可你的理解,例如Handler机制,这个是面试必问之题。有些晦涩的点,或许它只活在面试当中,实际工作当中你压根不会用到它,但是你要知道它是什么东西。
最后在这里小编分享一份自己收录整理上述技术体系图相关的几十套腾讯、头条、阿里、美团等公司20年的面试题,把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分。
还有 高级架构技术进阶脑图、Android开发面试专题资料,高级进阶架构资料 帮助大家学习提升进阶,也节省大家在网上搜索资料的时间来学习,也可以分享给身边好友一起学习。
【Android核心高级技术PDF文档,BAT大厂面试真题解析】
[外链图片转存中…(img-FZ4GYZ61-1715255248434)]
【算法合集】
[外链图片转存中…(img-Rc42ictn-1715255248434)]
【延伸Android必备知识点】
[外链图片转存中…(img-uuKVfHMq-1715255248435)]
《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门,即可获取!