You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.1 KiB
107 lines
3.1 KiB
package com.project.survey.ui
|
|
|
|
import androidx.fragment.app.Fragment
|
|
import androidx.fragment.app.FragmentManager
|
|
import androidx.fragment.app.FragmentPagerAdapter
|
|
import androidx.viewpager.widget.ViewPager
|
|
import com.bingce.ui.TabEntity
|
|
import com.flyco.tablayout.listener.CustomTabEntity
|
|
import com.flyco.tablayout.listener.OnTabSelectListener
|
|
import com.project.survey.R
|
|
import com.project.survey.ui.base.BaseBindingActivity
|
|
import com.project.survey.databinding.ActivityMainBinding
|
|
import com.project.survey.ui.home.HomeFragment
|
|
import com.project.survey.ui.home.InstrumentFragment
|
|
import com.project.survey.ui.home.MeFragment
|
|
|
|
|
|
class MainActivity : BaseBindingActivity<ActivityMainBinding>() {
|
|
|
|
private val mFragments = mutableListOf<Fragment>()
|
|
|
|
override fun getBinding(): ActivityMainBinding {
|
|
return ActivityMainBinding.inflate(layoutInflater)
|
|
}
|
|
|
|
override fun initView() {
|
|
|
|
initTabFragment()
|
|
|
|
}
|
|
|
|
private fun initTabFragment() {
|
|
//设置tab
|
|
val mTabEntities = ArrayList<CustomTabEntity>()
|
|
mTabEntities.add(
|
|
TabEntity(
|
|
"首页",
|
|
R.mipmap.icon_home_selected,
|
|
R.mipmap.icon_home_selected_not
|
|
)
|
|
)
|
|
mTabEntities.add(
|
|
TabEntity(
|
|
"仪器",
|
|
R.mipmap.icon_instrument_selected,
|
|
R.mipmap.icon_instrument_selected_not
|
|
)
|
|
)
|
|
mTabEntities.add(
|
|
TabEntity(
|
|
"我的",
|
|
R.mipmap.icon_me_selected,
|
|
R.mipmap.icon_me_selected_not
|
|
)
|
|
)
|
|
mBinding.tabLayout.setTabData(mTabEntities)
|
|
|
|
mBinding.tabLayout.setOnTabSelectListener(object : OnTabSelectListener {
|
|
override fun onTabSelect(position: Int) {
|
|
mBinding.vp.setCurrentItem(position)
|
|
}
|
|
|
|
override fun onTabReselect(position: Int) {
|
|
}
|
|
})
|
|
|
|
//设置viewPager
|
|
mFragments.add(HomeFragment())
|
|
mFragments.add(InstrumentFragment())
|
|
mFragments.add(MeFragment())
|
|
mBinding.vp.adapter = MyPagerAdapter(supportFragmentManager)
|
|
mBinding.vp.offscreenPageLimit = 3
|
|
mBinding.vp.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
|
|
override fun onPageScrolled(
|
|
position: Int,
|
|
positionOffset: Float,
|
|
positionOffsetPixels: Int
|
|
) {
|
|
}
|
|
|
|
override fun onPageSelected(position: Int) {
|
|
mBinding.tabLayout.currentTab = position
|
|
}
|
|
|
|
override fun onPageScrollStateChanged(state: Int) {
|
|
}
|
|
|
|
})
|
|
}
|
|
|
|
override fun initData() {
|
|
}
|
|
|
|
private inner class MyPagerAdapter : FragmentPagerAdapter {
|
|
constructor(fm: FragmentManager) : super(fm)
|
|
|
|
constructor(fm: FragmentManager, behavior: Int) : super(fm, behavior)
|
|
|
|
override fun getItem(position: Int): Fragment {
|
|
return mFragments[position]
|
|
}
|
|
|
|
override fun getCount(): Int {
|
|
return mFragments.size
|
|
}
|
|
}
|
|
} |