优化了事件面板的整体展示tab切换功能
This commit is contained in:
@@ -1,17 +1,10 @@
|
||||
package com.mogo.module.v2x.fragment
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Typeface
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import android.widget.RadioGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import com.google.android.material.tabs.TabLayoutMediator.TabConfigurationStrategy
|
||||
import com.mogo.commons.mvp.MvpFragment
|
||||
import com.mogo.module.v2x.R
|
||||
import com.mogo.module.v2x.V2XConst.MODULE_NAME
|
||||
@@ -36,12 +29,6 @@ class V2XEventPanelFragment : MvpFragment<V2XEventPanelFragment, EventPanelPrese
|
||||
|
||||
private var mediator: TabLayoutMediator? = null
|
||||
|
||||
private val activeColor: Int = android.graphics.Color.parseColor("#FFFFFF")
|
||||
private val normalColor: Int = android.graphics.Color.parseColor("#65FFFFFF")
|
||||
|
||||
private val activeSize = 20
|
||||
private val normalSize = 20
|
||||
|
||||
private var selectPosition = 0
|
||||
|
||||
companion object {
|
||||
@@ -56,7 +43,7 @@ class V2XEventPanelFragment : MvpFragment<V2XEventPanelFragment, EventPanelPrese
|
||||
}
|
||||
|
||||
override fun initViews() {
|
||||
Logger.d(MODULE_NAME, "EventPanelFragment init view===")
|
||||
Logger.d(MODULE_NAME, "事件面板初始化……")
|
||||
fragments = arrayOf(
|
||||
V2XScenarioHistoryFragment(),
|
||||
SurroundingEventFragment(),
|
||||
@@ -65,67 +52,38 @@ class V2XEventPanelFragment : MvpFragment<V2XEventPanelFragment, EventPanelPrese
|
||||
//禁用预加载
|
||||
vpEventPanel.offscreenPageLimit = ViewPager2.OFFSCREEN_PAGE_LIMIT_DEFAULT
|
||||
vpEventPanel.adapter = V2XEventPagerAdapter(this, fragments!!)
|
||||
//viewPager 页面切换监听
|
||||
vpEventPanel.registerOnPageChangeCallback(changeCallback)
|
||||
vpEventPanel.isUserInputEnabled = false; //true:滑动,false:禁止滑动
|
||||
|
||||
/*TabLayout中间分界线*/
|
||||
val linearLayout: LinearLayout = tabLayout.getChildAt(0) as LinearLayout
|
||||
linearLayout.showDividers = LinearLayout.SHOW_DIVIDER_MIDDLE
|
||||
linearLayout.dividerDrawable = activity?.let { ContextCompat.getDrawable(it, R.drawable.bg_v2x_event_live_show) }
|
||||
linearLayout.dividerPadding = 30
|
||||
val radioGroup = findViewById<View>(R.id.rgTabSelect) as RadioGroup?
|
||||
radioGroup!!.setOnCheckedChangeListener { group, checkedId ->
|
||||
when (checkedId) {
|
||||
R.id.rbScenarioHistory -> {
|
||||
vpEventPanel.setCurrentItem(0, false)
|
||||
}
|
||||
R.id.rbSurroundingEvent -> {
|
||||
vpEventPanel.setCurrentItem(1, false)
|
||||
}
|
||||
R.id.rbShareEvents -> {
|
||||
vpEventPanel.setCurrentItem(2, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//这里可以自定义TabView
|
||||
mediator = TabLayoutMediator(tabLayout, vpEventPanel, TabConfigurationStrategy { tab, position ->
|
||||
val tabView = TextView(context)
|
||||
tabView.gravity = Gravity.CENTER
|
||||
val states = arrayOfNulls<IntArray>(2)
|
||||
states[0] = intArrayOf(android.R.attr.state_selected)
|
||||
states[1] = intArrayOf()
|
||||
val colors = intArrayOf(activeColor, normalColor)
|
||||
val colorStateList = ColorStateList(states, colors)
|
||||
tabView.text = tabsTitle[position]
|
||||
tabView.textSize = normalSize.toFloat()
|
||||
tabView.typeface = Typeface.DEFAULT_BOLD
|
||||
tabView.setTextColor(colorStateList)
|
||||
tab.customView = tabView
|
||||
})
|
||||
//要执行这一句才是真正将两者绑定起来
|
||||
mediator!!.attach()
|
||||
btnHidePanels.setOnClickListener {
|
||||
hidePanel()
|
||||
}
|
||||
|
||||
btnShowOrHidePanels.setOnClickListener {
|
||||
if (clPanelContainer.visibility == View.GONE) {
|
||||
showPanel()
|
||||
// 选中指定的Tab
|
||||
tabLayout.getTabAt(selectPosition)?.select()
|
||||
vpEventPanel.setCurrentItem(selectPosition, false)
|
||||
} else {
|
||||
hidePanel()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val changeCallback: OnPageChangeCallback = object : OnPageChangeCallback() {
|
||||
override fun onPageSelected(position: Int) {
|
||||
selectPosition = position
|
||||
//可以来设置选中时tab的大小
|
||||
val tabCount = tabLayout.tabCount
|
||||
for (i in 0 until tabCount) {
|
||||
val tab = tabLayout.getTabAt(i)
|
||||
val tabView = tab!!.customView as TextView?
|
||||
if (tab.position == position) {
|
||||
tabView!!.textSize = activeSize.toFloat()
|
||||
tabView.typeface = Typeface.DEFAULT_BOLD
|
||||
} else {
|
||||
tabView!!.textSize = normalSize.toFloat()
|
||||
tabView.typeface = Typeface.DEFAULT
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
mediator?.detach()
|
||||
vpEventPanel?.unregisterOnPageChangeCallback(changeCallback)
|
||||
super.onDestroyView()
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:color="#65FFFFFF" android:state_checked="false" />
|
||||
<item android:color="#FFFFFF" android:state_checked="true" />
|
||||
</selector>
|
||||
@@ -10,46 +10,91 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#10121E"
|
||||
android:paddingStart="@dimen/dp_30"
|
||||
android:paddingEnd="@dimen/dp_30"
|
||||
android:visibility="gone"
|
||||
app:roundLayoutRadius="@dimen/dp_40"
|
||||
tools:visibility="visible">
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/tabLayout"
|
||||
<RadioGroup
|
||||
android:id="@+id/rgTabSelect"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dp_130"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:tabGravity="fill"
|
||||
app:tabIndicatorFullWidth="false"
|
||||
app:tabIndicatorHeight="2dp"
|
||||
app:tabMode="scrollable"
|
||||
app:tabSelectedTextColor="#FFFFFF"
|
||||
app:tabTextColor="#65FFFFFF"
|
||||
app:tabUnboundedRipple="true" />
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbScenarioHistory"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:button="@null"
|
||||
android:checked="true"
|
||||
android:gravity="center"
|
||||
android:paddingStart="@dimen/dp_40"
|
||||
android:paddingEnd="@dimen/dp_40"
|
||||
android:text="出行动态"
|
||||
android:textColor="@color/radiobutton_textcolor"
|
||||
android:textSize="@dimen/dp_40"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<View
|
||||
android:layout_width="2dp"
|
||||
android:layout_height="@dimen/dp_42"
|
||||
android:background="#757575" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbSurroundingEvent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:button="@null"
|
||||
android:gravity="center"
|
||||
android:paddingStart="@dimen/dp_40"
|
||||
android:paddingEnd="@dimen/dp_40"
|
||||
android:text="周边事件"
|
||||
android:textColor="@color/radiobutton_textcolor"
|
||||
android:textSize="@dimen/dp_40"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<View
|
||||
android:layout_width="2dp"
|
||||
android:layout_height="@dimen/dp_42"
|
||||
android:background="#757575" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbShareEvents"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:button="@null"
|
||||
android:gravity="center"
|
||||
android:paddingStart="@dimen/dp_40"
|
||||
android:paddingEnd="@dimen/dp_40"
|
||||
android:text="我的分享"
|
||||
android:textColor="@color/radiobutton_textcolor"
|
||||
android:textSize="@dimen/dp_40"
|
||||
android:textStyle="bold" />
|
||||
</RadioGroup>
|
||||
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/vpEventPanel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:overScrollMode="never"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tabLayout" />
|
||||
|
||||
app:layout_constraintTop_toBottomOf="@+id/rgTabSelect" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/btnHidePanels"
|
||||
android:layout_width="@dimen/dp_88"
|
||||
android:layout_height="@dimen/dp_88"
|
||||
android:layout_marginEnd="@dimen/dp_40"
|
||||
android:background="@drawable/v2x_icon_event_live_close"
|
||||
android:textColor="#000"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/tabLayout"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/rgTabSelect"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/tabLayout" />
|
||||
app:layout_constraintTop_toTopOf="@+id/rgTabSelect" />
|
||||
|
||||
</com.mogo.module.v2x.view.RoundConstraintLayout>
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="@dimen/dp_60"
|
||||
android:paddingTop="@dimen/dp_30"
|
||||
android:paddingEnd="@dimen/dp_60"
|
||||
android:paddingBottom="@dimen/dp_30"
|
||||
android:text="今日出行遇到的交通事件"
|
||||
android:textColor="#FFFFFF"
|
||||
@@ -32,8 +30,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:overScrollMode="never"
|
||||
android:paddingStart="@dimen/dp_40"
|
||||
android:paddingEnd="@dimen/dp_40"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:listitem="@layout/item_v2x_illegal_parking" />
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
@@ -15,4 +15,8 @@
|
||||
<item name="android:stepSize">0.5</item>
|
||||
<item name="android:progressDrawable">@drawable/share_rating_bar</item>
|
||||
</style>
|
||||
|
||||
<style name="customTabLayoutTextAppearance" parent="TextAppearance.Design.Tab">
|
||||
<item name="android:textSize">@dimen/dp_40</item>
|
||||
</style>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user